Sunday, 25 February 2018

Adding comma using STUFF in Sql Server

1.select distinct id,name,
STUFF((select ','+descrptn from test t1 where t2.id=t1.id for xml path('')),1,1,'') as description
from test t2


2.SELECT DISTINCT StateId, StateName
, STUFF((SELECT ','+City
FROM [StateProvince] S2
WHERE S1.StateId = S2.StateId
FOR XML PATH('')), 1, 1, '') AS City
FROM [StateProvince] S1

No comments:

Post a Comment