Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want this output , how to write query in sql server?

col1 col2 col2

m1 1 a
m1 1 b
m1 1 c
m2 2 d
m2 2 e
m2 1 f

output
---------

m1 1,a,b,c,f
m2 2,d,e
Posted
Comments
dan!sh 21-Jul-14 0:57am    
You want a comma separated value in the result?
dan!sh 21-Jul-14 2:02am    
I tried posting a comment asking OP what does he want to display.
Magic Wonder 21-Jul-14 2:16am    
Hey d@nish...sorry that reply was mistakenly posted on yours reply.
dan!sh 21-Jul-14 2:17am    
No problem. I wasn't serious.
Magic Wonder 21-Jul-14 2:18am    
yeah...

1 solution

Just try this,

select col1,col2, stuff((select','+ t1.col3 from Test t1 where t1.col1=t2.col1 FOR XML PATH('')),1,1,'') as result from Test t2 group by col1,col2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900