Forum Discussion
Error When Running The Code: Incorrect syntax near the keyword 'CASE'
Hi,
I need help on these codes because I'm getting the error as shown from the subject. FYI. gbkmut.bdr_hfl are numeric values
CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN gbkmut.bdr_hfl
ELSE NULL
END AS Debit,
CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN NULL
ELSE -gbkmut.bdr_hfl
END AS Credit
Good to hear that your problem is solved!
Just add a comma behind the * and the quety will give you all the columns in the table.
6 Replies
- AnonymousNot applicable
"601"{[Schema="dbo",Item="gbkmut"]}[Data] - Forgot to add this one
- SmalflyResponsive Resident
Hi Anonymous ,
for your printscreen I don't see the whole SQL query but it needs to be a query that runs on its own in your SQL evironment. So it will be something like select columnA, columnB from TableX.
If your query looks correct, try running it in your SQL environment. That might give you a more meaningful error.
Good luck!
- AnonymousNot applicable
I still got the same error...
SELECT gbkmut.reknr, gbkmut.bdr_hfl
CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN gbkmut.bdr_hfl
ELSE NULL
END AS Debit,SELECT gbkmut.reknr, gbkmut.bdr_hfl
CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN NULL
ELSE -gbkmut.bdr_hfl
END AS Credit- SmalflyResponsive Resident
Try this:
SELECT gbkmut.reknr, gbkmut.bdr_hfl,
CASE WHEN gbkmut.transtype IN ('N','C','P','F') AND gbkmut.transsubtype NOT IN ('R','S') AND gbkmut.bdr_hfl >= 0 OR gbkmut.transsubtype IN ('R','S') AND gbkmut.bdr_hfl < 0
THEN gbkmut.bdr_hfl
ELSE NULL END AS Debit,
CASE WHEN gbkmut.transtype IN ('N','C','P','F') AND gbkmut.transsubtype NOT IN ('R','S') AND gbkmut.bdr_hfl >= 0 OR gbkmut.transsubtype IN ('R','S') AND gbkmut.bdr_hfl < 0
THEN NULL ELSE -gbkmut.bdr_hfl END AS Credit
FROM gbkmutWhat I did:
* I added a comma behind gbkmut.bdr_hfl
* I removed your second select statement
* I added a from statement in which I assumed gbkmut is your table name