在 SQL Server 2017 之前實作字串聚合
對於使用 SQL Server 2014 或更早版本並希望像範例查詢那樣連接字串的使用者:
select string_agg(t.id,',') AS id from Table t
以下是您可以針對您的環境調整此查詢的方法:
select stuff( (select ',' + cast(t.id as varchar(max)) from tabel t for xml path ('') ), 1, 1, '' );
在這個查詢中,stuff()
函數只用來移除開頭的逗號。實際的字串連接是使用 for xml path
完成的。
以上是2017年之前的SQL Server如何實現字串聚合?的詳細內容。更多資訊請關注PHP中文網其他相關文章!