I am doing this:
, cte_proc_code (accn,proc_code) as
(SELECT accn_id,
(SELECT proc_code + ','
FROM [XDataFullExtract].[dbo].[accn_billed_procedures]
FOR XML PATH('')
)
FROM [XDataFullExtract].[dbo].[accn_billed_procedures]
group by accn_id)
My data looks like this:
accn_id,proc_code
AA123, 1132
AA123, 5234
AA123, 4524
BB123, 2345
BB123, 4444
The result that I would like is:
accn_id,proc_code
AA123, 1132, 5234, 4524
BB123, 2345, 4444
My solution works however IT'S WAY TOO SLOW!!
Is there a faster way to do this? I think the XML is slowing me down.
dbo.accn_billed_procedures? Is there any index that involves bothaccn_idandproc_code? Is there any reason you're pulling the whole table with noWHEREclause? Details, details, details...