SQL server combining rows to columns -


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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -