Comma Separated values with SQL Query

后端 未结 4 882
孤街浪徒
孤街浪徒 2020-11-30 06:00

My SQL table is like following

City_Code     Post_Code    Post_Code_Description
100           A1           ABC
100           C8           XYZ
100           Z         


        
4条回答
  •  庸人自扰
    2020-11-30 06:33

    try this:

    select city_code,substring((select ',' + post_code  
    from city b where a.city_code=b.city_code
    for xml path('')
    ),2,100)as post_code,
    substring((select ',' + post_code_description 
    from city c where a.city_code=c.city_code
    for xml path('')
    ),2,100)as post_code_description
    from city a
    group by a.city_code
    

提交回复
热议问题