I have following XML value in one of the column of table.
<wizard id="CF510D2B-BF9C-485B-9D33-0056D1DDFDF2" step="4" sbm="1C766093-633D-E611-80C2-40F2E9DD0D2A">
<reviews>
<crd id="AE7F8E74-643D-E611-80C2-40F2E9DD0D2A" />
<rvw id="AF7F8E74-643D-E611-80C2-40F2E9DD0D2A" />
<rvw id="B07F8E74-643D-E611-80C2-40F2E9DD0D2A" />
</reviews>
</wizard>
Using following query
SELECT abc = STUFF((
SELECT ',' +CAST(w.[state].value('(/wizard/reviews/rvw/@id)[1]', 'uniqueidentifier') AS varchar(max))
FROM dbo.Wizard w where code='1C766093-633D-E611-80C2-40F2E9DD0D2A'
FOR XML PATH('')
), 1, 1, '')
FROM dbo.Wizard w
Output:
AF7F8E74-643D-E611-80C2-40F2E9DD0D2A
Desired output:
AF7F8E74-643D-E611-80C2-40F2E9DD0D2A,B07F8E74-643D-E611-80C2-40F2E9DD0D2A