Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WITHIN GROUP (ORDER BY Id) does not work on Microsoft SQL Server 2017 (Build 14.0.3076.1)

5 views
Skip to first unread message

va

unread,
Jun 4, 2020, 11:07:25 AM6/4/20
to
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!
0 new messages