I\'ve written this query with the help of google to create a delimited list from a table but I didn\'t understand anything from this query.
Can anyone explain me wha
SQL Server 2017 makes this much easier with the new STRING_AGG. Recently came across this post and switched my STUFF/FOR XML strategy to use the new string function. Also avoids the need to do an extra JOIN/SUBQUERYand the overhead of FOR XML (and the odd-encoding issues) and hard to interpret SQL.
SELECT E1.deptno,
STRING_AGG(E1.ename, ', ') AS allemp
FROM EMP AS e1
GROUP BY DEPTNO;
Note: Also be sure to check out the counterpart STRING_SPLIT to make working with SQL delimited data much easier.