sql if

barski

Well-known member
Joined
Apr 7, 2002
Messages
239
Location
Tennessee
if have something like

date sales
3/1/2004 1000
3/31/2004 2000

if the date is less than 3/15/2004 then multiply sales by 2

using a case i can handle true/false expressions but how do i handle > and <?
 
Code:
SELECT *, 
  (
  CASE 
    WHEN DAY([Date]) BETWEEN 1 AND 14 THEN [Sales]*2 
    ELSE [Sales] 
  END
  ) As [SalesAdjusted]

FROM [YourTable]
 
thanks a bunch!! i kept using

case field1 when < 1

.... or whatever the error in my logic or lack of is obvious
 
I was just using "BETWEEN" to show whats going on. You could use an equality operator as well:
Code:
SELECT *, 
  (
  CASE 
    WHEN DAY([Date]) < 15 THEN [Sales]*2 
    ELSE [Sales] 
  END
  ) As [SalesAdjusted]

FROM [YourTable]
 
Back
Top