Sql Query for multiple items returns in comma seperated model

Posted by Amritha444 under Sql Server on 8/4/2014 | Points: 10 | Views : 1031 | Status : [Member] | Replies : 2
Hi all

Select * from table_details returns


Code Salesman date status

1 s1 1/1/2014 Y
2 s2 2/1/2014 Y
2 s1 2/1/2014 Y
3 s2 3/1/2014 Y


i want query to return rows like

Code Salesman date status

1 s1 1/1/2014 Y
2 s2,s1 2/1/2014 Y
3 s2 3/1/2014 Y

How to do this

Thanks in Advance

Amritha




Responses

Posted by: Bandi on: 8/4/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down

SELECT distinct Code
,STUFF((SELECT ','+Salesman from table_details where Code=t.Code for xml path('')), 1,1, '')SalesMan
,date
,status
FROM table_details t


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/5/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Mark as Answer if got clear idea/solution...

Post us back the issue/doubts if not resolved the issue

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response