SQL comparisons

34 Views Asked by At
case when 3<myInputValue<6then 
          --do something
     when 6<myInputValue<9 then 
          --do something
     when 9<myInputValue<12 then 
          --do something
end

how to achieve this 2 comparison as a single expression?

group by DATENAME(month,DATEADD(QUARTER,1, GETDATE()))

I need to 'group by' the datas by future quarters for expected revenues for the next years, how to achieve that too?

2

There are 2 best solutions below

4
Michał Turczyn On

For example first condition should be rewritten as: 3 < myInputValue AND myInputValue < 6.

0
swe On

because "CASE" returns the value of the FIRST true condition you can just do

case when myInputValue<3then 
      --do nothing
 when myInputValue<6then 
      --do something
 when myInputValue<9 then 
      --do something
 when myInputValue<12 then 
      --do something
end