26
Views
4
Comments
Error in advanced query SQL1: Incorrect syntax near the keyword 'SELECT'. Incorrect

Hi,

I'm trying to return JSON from SQL and I'm getting this error. Can anyone explain why this is happening?

Database returned the following error: Error in advanced query SQL1: Incorrect syntax near the keyword 'SELECT'. Incorrect syntax near 'JSON_OBJECT'. 


2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @Mohan Raja ,

The error indicates that there is a syntax error in your SQL. To be able to determine what's the actual error we need to see the SQL you are trying to run. Please copy it here.

2025-12-22 13-50-43
Sherif El-Habibi
Champion

Hello,

Just to clarify your question: do you mean that you are trying to write a JSON format inside an Advanced Query, or have you already written the query and now want the output in JSON format? 

2019-01-07 16-04-16
Siya
 
MVP

@Mohan Raja : Do you mind sharing your SQL query and maybe the data model?

2025-12-18 01-28-51
Peter Hieu

Hi @Mohan Raja 

SQL Server doesn’t support JSON_OBJECT, so the error occurs. In OutSystems (SQL Server), you must build JSON using:

SELECT ... FOR JSON PATH

or:

FOR JSON PATH, WITHOUT_ARRAY_WRAPPER

* This is the correct and only supported way to return JSON in an Advanced Query.

Hope this helps,

Peter Hieu

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