There is a bug in your code in
WHEN (belowthen2 < 2 and between2and5 between 2 and 5 and above5 >5 ) THEN 'Above' and ELSE 'Below'
Remove the
and
that I've highlighted
There are some good examples on how to have multiple conditions in a
CASE
statement on the documentation site -
CASE (Transact-SQL) | Microsoft Docs[
^]
Here is a trivial example using this sample data:
create table #example (a int)
insert into #example (a) values (0),(25), (50), (100)
This query has 4 conditions
select CASE WHEN a < 25 THEN '1st Quartile'
WHEN a < 50 THEN '2nd Quartile'
WHEN a < 75 THEN '3rd Quartile'
ELSE '4th Quartile'
END,a
FROM #example
giving the results
1st Quartile 0
2nd Quartile 25
3rd Quartile 50
4th Quartile 100
Here is a slightly more complex example
create table #example2 (a int, b int, c int, d int)
insert into #example2 (a,b,c,d) values
(1,0,0,0), (2,1,0,0), (1,1,0,0), (1,0,0,1)
select CASE WHEN a = 1 and d = 0 THEN 'Condition 1'
WHEN a = 1 and b = 1 and c = 1 and d = 1 THEN 'Condition 2'
ELSE
'No conditions met'
END
from #example2
Unfortunately you haven't given us your complete query, nor any sample data or expected results so I can't help you with your specific problem