Hi
Incorrect Syntax near Then
Select case When (Select "GSTIN" from CRD1 where "CardCode" = OPCH."CardCode" And "GSTIN" = '' Then 'GA' else 'GA' End) from OPCH
Thanks
Hi
Incorrect Syntax near Then
Select case When (Select "GSTIN" from CRD1 where "CardCode" = OPCH."CardCode" And "GSTIN" = '' Then 'GA' else 'GA' End) from OPCH
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Apr 9, 2025, 8:05 AM
Hello Ramco,
You can use this query,
Sophia CarterPosted Apr 9, 2025, 5:56 AM
Certainly! The issue in the SQL query you provided lies in the incorrect placement of the `Then` keyword within the `CASE` statement. In SQL, the correct syntax for a `CASE` statement is `CASE WHEN condition THEN result ELSE else_result END`.
Here's the corrected version of your SQL query:
In the corrected query:
- We've moved the condition `(SELECT "GSTIN" FROM CRD1 WHERE "CardCode" = OPCH."CardCode" AND "GSTIN" = '') = 'GA'` within the `WHEN` clause.
- Changed the `THEN 'GA' else 'GA'` to `THEN 'GA' ELSE 'Other Value'`.
This revised query should now operate correctly, checking if the subquery returns 'GA' and then outputting 'GA'; otherwise, it will output 'Other Value'.
If you have any further questions or need more clarification, feel free to ask!