Tuesday 4 December 2018

Convert rows into comma seperated - (SQL Server) - using XML path


Use XML path and stuff the values into comma seperated


select distinct
--Check the null in the CPTCode
(STUFF((SELECT top 100 percent LTRIM(RTRIM( + case when isnull(cl.CPTCode,'')<>'' then ',' else '' end+isnull(cl.CPTCode,'')))
FROM  ClaimLineEdit as cl with(nolock)
WHERE audit_id = a.id
--Convert to XML path
FOR XML PATH (''),type).value('(./text())[1]','varchar(max)'), 1, 1, '')) [Revised CPT Code]
from audit as a with(nolock)
inner join flow as f with(nolock)  on a.Flow_id=f.Id
inner join  Claim as cs with(nolock) on a.ClaimSummaryUid=cs.ClaimSummaryUID
inner join Status as s with(nolock) on a.Substatus_id=s.Id and a.Flow_id=s.Flow_id
where a.Id in (1,2,3,)

No comments:

Post a Comment