1. 程式人生 > >資料庫將多行資料合併為一行資料

資料庫將多行資料合併為一行資料

先看資料庫:

假如我們執行這樣的語句 select * from sh_meetingservice where id in(1,2,3);結果如下會有多行

但是我們想要多行合併為一行,我們需要用到 for xml path

select text+',' from sh_meetingservice  where id in (1,2,3) for xml path('myApp');

for xml path('')節點為空;for xml path預設;for xml path('myApp')自定義返回

然後在執行

select (select text+',' from sh_meetingservice  where id in (1,2,3) for xml path('')  ) as txt ;