Groups | Search | Server Info | Login | Register
Groups > microsoft.public.de.sqlserver > #9
| Newsgroups | microsoft.public.de.sqlserver |
|---|---|
| Date | 2020-06-04 08:07 -0700 |
| Message-ID | <ef1cec64-5ef1-4b68-985d-be34054f6ad5@googlegroups.com> (permalink) |
| Subject | WITHIN GROUP (ORDER BY Id) does not work on Microsoft SQL Server 2017 (Build 14.0.3076.1) |
| From | va <matthiasvonah@gmail.com> |
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!
Back to microsoft.public.de.sqlserver | Previous | Next | Find similar
WITHIN GROUP (ORDER BY Id) does not work on Microsoft SQL Server 2017 (Build 14.0.3076.1) va <matthiasvonah@gmail.com> - 2020-06-04 08:07 -0700
csiph-web