SQL Server 2012 Columns to Single Row Seperated by Comma -
i have table sortorder , diagnosiscodes.
i need see diagnosiscodes in 1 row each different set of sortorders.
use xml path
declare @diagnosis table (id int, diagnosiscode varchar(10)) insert @diagnosis values (1,'d50.9'), (1,'m10.9'), (1,'z79.82'), (2,'m81.0'), (2,'z85.3'), (2,'z90.710'), (3,'m81.0'), (3,'z85.3'), (3,'z17.0') select t.id, stuff(( select ', ' + diagnosiscode @diagnosis id = t.id xml path(''),type) .value('.','nvarchar(max)'),1,2,'') alldiagnosiscodes @diagnosis t group t.id order t.id
result
id alldiagnosiscodes 1 d50.9, m10.9, z79.82 2 m81.0, z85.3, z90.710 3 m81.0, z85.3, z17.0
Comments
Post a Comment