Actually, STUFF() doesn't generate anything. It just replaces the first comma in the string with the emptiness. The string is generated by FOR XML.
Anyway, this approach is very good and I use it quite often. But SQL Server version 2017 and higher has another very good function STRING_AGG()
Just for information, because your version is 2016.
For instance your example will be looking like the code below:
Thanks @rozhnev for your great tool (not sponsored)! I just have SQL Server V.2014 on my machine and it's difficult to show new functionality using it.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually, STUFF() doesn't generate anything. It just replaces the first comma in the string with the emptiness. The string is generated by
FOR XML.Anyway, this approach is very good and I use it quite often. But SQL Server version 2017 and higher has another very good function STRING_AGG()
Just for information, because your version is 2016.
For instance your example will be looking like the code below:
This is the result:
Thanks @rozhnev for your great tool (not sponsored)! I just have SQL Server V.2014 on my machine and it's difficult to show new functionality using it.