Hi all,
I am trying to run this Query, which should give me a string of Id's in ascending order:
select
Description,
Typ,
string_agg(
test.id,',') WITHIN GROUP (ORDER BY
test.id ASC) as MetaIdList,
count(id) as NumberOfRows
from test
Group by
Description,
Typ
Having count(id) > 1
Without "WITHIN GROUP (ORDER BY
test.id)" it works fine and gives the following results:
Description Typ MetaIdList NumberOfRows
Desc1 NULL 8606,10695 2
Desc2 NULL 18606,10695 2....
But it lacks sorting of ID's in [MetaIdList], which is needed for my case.
According MS documentation the query should be fine.
But I get the following error:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '('.
We are using MS SQL Server 2017 (Build 14.0.3076.1)
Can anybody help?
Thanks in advance!