86
Views
2
Comments
STRING_AGG function with ORDER BY in SQL advanced query
Application Type
Reactive

Hi everyone,

I am using the STRING_AGG function within a CTE and it's working just fine (line 11 of the image below).

However, I would like to apply an order by clause do the Agg function like i wrote in line 10.

When I run que query in SQL Server it works just fine and I get the expected output, however when I test the same exact query in service studio I get an error and the same happens when the application tries to run the query.

I am not sure if has something to do with outsystems built in database engine that utilizes a different syntax for this purpose or if has something to do with database versions also possibly affecting the syntax.

I also tried to run SELECT STRING_AGG ({CONTRAPARTES}.[Nome], ', ' order by {CONTRAPARTES}.[Nome]) but also received an error.

If anyone has any idea on how to apply the ORDER BY clause the the STRING_AGG function in outsystems or has any other alternative that would give me the same expected output I would really appreciate it.

Thank you everyone!

2023-02-13 15-34-45
BabyBear

Hi What version of ms sql are you using in your Outsystems Infrastructure?

String_agg function is only for MS SQL 2017 and up 

https://learn.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql?view=sql-server-ver16


2023-11-07 18-53-22
José Rodrigues

We're using SQL Server 2017

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.