Link to home
Start Free TrialLog in
Avatar of finance_teacher
finance_teacher

asked on

Microsoft SQL -- "ELSE IF" ?

Below #1 works.

How can I get the below #2 "ELSE IF" working ?
---------------------------------------------------------------------------
#1

UPDATE TIME_SCANNING
SET Status = 'STOP',
    TotalTime =
        CASE
        WHEN (DATEPART(HOUR, DateTime) < 11) OR
             (DATEPART(HOUR, DateTime) = 11 AND DATEPART(MINUTE, DateTime) < 15)
         THEN (cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) - .5)/ Qty
         ELSE
         cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) / Qty
        END
---------------------------------------------------------------------------
#2

UPDATE TIME_SCANNING
SET Status = 'STOP',
    TotalTime =
        CASE
        WHEN (DATEPART(HOUR, DateTime) < 11) OR
             (DATEPART(HOUR, DateTime) = 11 AND DATEPART(MINUTE, DateTime) < 15)
         THEN (cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) - .5)/ Qty
         ELSE IF (DATEPART(HOUR, DateTime) = 13)        
         cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) / Qty
         ELSE
           -- nothing
        END
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

CASE
  WHEN x THEN y
  WHEN a THEN b   -- Just keep adding when..then blocks, and not else if within a case
  END
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial