string_agg と for xml path

before Sqlserver2017
select
replace((select Column as [data()] from Table for xml path()),’ ‘,’,’) as CSVcolumn

Sqlserver2017
select
string_agg(Column,’,’) as CSVcolumn from Table

before Sqlserver2017
select
Z.PKcolumn
,Z.columnA
,Z.columnB
,row_number() over (order by Z.columnB asc) Seq
,replace((select Z.columnD as [data()] from Table where Z.PKcolumn=PKcolumn for xml path(”)),’ ‘,’,’) Member
from Table as Z
group by PKcolumn,columnA,columnB

Sqlserver2017
select
Z.PKcolumn
,Z.columnA
,Z.columnB
,row_number() over (order by Z.columnB asc) Seq
,string_agg(Z.columnD,’,’) Member
from Table as Z
group by PKcolumn,columnA,columnB

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です