Search This Blog

Wednesday, February 20, 2013

How to concatenate columns separated by comma using sql xml.

Concatenate the Revision against soft
SoftRevision
11
12
13
22
24
35


Select Soft , LEFT(Revision , LEN(Revision)-1) as Revision
FROM
(
Select Soft,
( Select Convert(VARCHAR,Revision)+',' from tblName x where x.soft= y.soft
for xml path('')
) as revision
from tblName y
group by soft
)ask

output
SoftRevision
11,2,3
22,4
35

No comments:

Post a Comment