I am trying to run this simple query however it doesn’t even parse saying
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword
‘between’.
Query is:
select
case DMProject.dbo.TypeFourTraining.Column2
when Column2 between 181 and 360 then '181-360'
when Column2 between 0 and 180 then '0-180'
END as score
from DMProject.dbo.TypeFourTraining
The same doesn’t work for Column2 < 360 syntax neither..
I have searched over internet from msdn, and some other sites but I see that my syntax seems to be valid, then either there is a detail I need to know or there is something I can’t see 🙁
Can anyone please suggest a solution?
You cannot mix the
simpleandsearchedtypes of CASE expression. Remove the field nameDMProject.dbo.TypeFourTraining.Column2specified after the CASE.Correct syntax for your query:
Two types of CASE expressions:
There are two types of CASE expression namely
SimpleandSearched. You cannot combine Simple and Searched in the same expression.Simple CASE:
Searched CASE with simple example:
Searched CASE with slightly complex example:
This involves multiple columns. You can add multiple columns in each of the WHEN statements.