StefanE
StefanE

Reputation: 7630

Use of CASE in Update query

I have following SQL (Using MS SQL)

UPDATE AR_Slots
SET Running = @Running,
StopSignal = @StopSignal,
WHERE (SlotId = @SlotId)

I want to set a field called RunListID to 0 if Running parameter (boolean) is true otherwise I don't want to change the value at all.

What is the "correct" way of doing this?

Thanks, Stefan

Upvotes: 1

Views: 261

Answers (1)

Adriaan Stander
Adriaan Stander

Reputation: 166606

Try something like

UPDATE AR_Slots
SET RunListID = 
    CASE
       WHEN <your check value>
          THEN 0
       ELSE RunListID
    END,
    <your other sets>
WHERE <your criteria>

Upvotes: 3

Related Questions