-1

I have sql server management studio 14.0.17825.0 and would like to use group_concat function. But I get error when i try to use. The error is invalid column name group_concat Is there any other function that I could use? Could you provide a sample code which could achieve what function group_concat?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
user2543622
  • 5,760
  • 25
  • 91
  • 159

1 Answers1

0

In SQL Server 2017+, the function is called string_agg():

select string_agg(col, ',') within group (order by col)

In earlier versions, you use a trick with XML, that might look like:

select stuff( (select ',' + col
               from t
               for xml path ('')
              ), 1, 1, ''
            )
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786