SQL server combining rows to columns -
this question has answer here:
i had problem in combining 2 rows in single column in sql server. here want original table this
-------------------------------------------- | id || d_code1 || d_code2 || dcode3 | -------- ---------- -------- -------- | 1 || 2f || v012 || f013 | | 1 || k013 || c190 || null | --------------------------------------------
i want loaded in this. bit complicated.
---------------------------------- | id || d_code | ---- ------------------------ | 1 || 2f,v012,f013,k013,c190 | ----------------------------------
could 1 please me on this. new sql server. in advance.
you can use stuff , xml
select distinct i.id [id], stuff(( select ',' + t.d_code1+' ,' +t.d_code2+' , '+t.d_code3 [text()] mytable t t.id = i.id xml path('') ), 1, 1, '' ) [dcode] mytable
Comments
Post a Comment