Home >Database >Mysql Tutorial >How to Achieve String Aggregation in SQL Server Before 2017?
Implementing string aggregation before SQL Server 2017
For those using SQL Server 2014 or earlier and want to concatenate strings like the example query:
<code class="language-sql">select string_agg(t.id,',') AS id from Table t</code>
Here's how you can tailor this query to your environment:
<code class="language-sql">select stuff( (select ',' + cast(t.id as varchar(max)) from tabel t for xml path ('') ), 1, 1, '' );</code>
In this query, the stuff()
function is only used to remove the leading comma. The actual string concatenation is done using for xml path
.
The above is the detailed content of How to Achieve String Aggregation in SQL Server Before 2017?. For more information, please follow other related articles on the PHP Chinese website!