String_agg()

hi
I am trying to use String_agg(0 function in my query But getting a error as
'string_agg' is not a recognized built-in function name.. Native error: 195. SQLSTATE: 42000. Severity 15. MsgState 10. Line 4.
i am on

SQL Server Management Studio 15.0.18131.0
Microsoft Analysis Services Client Tools 15.0.1347.0
Microsoft Data Access Components (MDAC) 10.0.14393.0
Microsoft MSXML 3.0 6.0
Microsoft Internet Explorer 9.11.14393.0
Microsoft .NET Framework 4.0.30319.42000
Operating System 10.0.14393

if it is not available in a given version
what is a workaround for this ?
Please help

looks like you are on older version than 2017.
Try using FOR XML PATH and STUFF as an alternate.

1 Like

okay

what are you trying to accomplish? Also please provide sample data and desired output?

declare @sample table(id int, name varchar(50))

insert into @sample
select 1, ' Hemu' union
select 2, 'Ahmed'  

I agree.... let's talk about what you're trying to do. The XML/STUFF method of aggregating strings i one way to do things but there are others.