select X, 
Y=stuff((select ','+Y from test t where X=b.X for xml path('')), 1, 1, '') 
from test b group by X