Hi
Incorrect syntax near Select
SELECT Sum(T1."SumApplied"),
(Select "Location" from OLCT where "Code" = (Select Max(A0."LocCode") from PCH1 A0 inner join OPCH A1 on A0."DocEntry" = A1."DocEntry"
where A0."DocEntry" In (Select "DocEntry" from VPM2 where "DocNum" = Select("CreatedBy" from OJDT where "TransId" = T0."TransId")))
) As "Location"
FROM OJDT T0 inner join VPM2 T1 On T1."DocNum" = T0."CreatedBy"
Thanks
Eliana BlakePosted Apr 25, 2025, 6:47 AM
The error "Incorrect syntax near Select" in the SQL query you provided is due to a misplaced or misused "Select" statement within the subquery. Here's a breakdown of the issue and how you can address it:
In the SQL query you provided:
The issue lies within this part:
To correct the syntax error, you need to adjust the subquery structure. The corrected subquery should have its own SELECT statement in parentheses and a comparison operator where needed. Here's a modified version of that part of the query:
By adding parentheses around the subquery and ensuring the SELECT statement is correctly positioned, you should be able to address the syntax error "Incorrect syntax near Select" in your SQL query.
If you make this adjustment, the query should execute without syntax errors. Always remember that correct syntax is crucial in SQL queries to ensure they are valid and produce the desired results.