Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How can we concatinate the values

Author  Topic 

boreddy
Posting Yak Master

172 Posts

Posted - 2011-07-21 : 03:56:30
Hi experts
i have one proble here
i have the data like this so many records

did issue change
2 data more
2 Null chang1
2 issue1 Null
4 issue4 change1
4 issu2 chen 4



i want disply the data like this

did issue change
2 data,issue1 more,chang1
4 issue4,issu2 change1,chen 4


how it possible to write in a single statement
with out using cursor and while loop


Thanks in advance


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-21 : 04:22:54
see

http://visakhm.blogspot.com/2010/01/multipurpose-apply-operator.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

eralper
Yak Posting Veteran

66 Posts

Posted - 2011-07-21 : 10:07:07
Hello boreddy,

You can try the following script
you can also check [url]http://www.kodyaz.com/articles/concatenate-using-xml-path.aspx[/url] for more samples

SELECT 
d.did,
STUFF(
(
SELECT ',' + issue
FROM done
WHERE did = d.did
FOR XML PATH('')
), 1, 1, '') as issue_list,
STUFF(
(
SELECT ',' + change
FROM done
WHERE did = d.did
FOR XML PATH('')
), 1, 1, '') as change_list
FROM (
Select distinct did from done
) d


I hope this helps,

-------------
Eralper
http://www.kodyaz.com
Go to Top of Page
   

- Advertisement -