Saturday, June 28, 2014

how to concat multiple rows with same id in sql


SELECT ID,
STUFF((SELECT ',' + FieldName
FROM Table
WHERE ID = t.ID
FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT ID FROM Table)t

If field has special characters like >,< etc use below


http://ift.tt/LSVild




Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://ift.tt/19nLNVq http://ift.tt/1iEAj0c


No comments:

Post a Comment