I\'m trying to aggregate a \'STRING\' field in SQLServer. I would like to find the same function LISTAGG like in Oracle .
Do you know how to do the same function or
This might be useful to someone also ..
i.e. For a data analyst and data profiling type of purposes ..(i.e. not grouped by) ..
Prior to the SQL*Server 2017 String_agg function existence ..
(i.e. returns just one row ..)
select distinct
SUBSTRING (
stuff(( select distinct ',' + [FieldB] from tablename order by 1 FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)')
,1,0,'' )
,2,9999)
from
tablename
e.g. returns comma separated values A,B