Rewind
Rewind

Reputation: 2814

MySql - Update/Case

I have a table Tests

TestNumber (int primary key)
InactiveBitwise (int)

I make the following command:

UPDATE tests SET CASE
        WHEN TestNumber = 2 THEN InactiveBitwise = (InactiveBitwise | 4)
        WHEN TestNumber = 3 THEN InactiveBitwise = (InactiveBitwise | 8)
END WHERE TestNumber IN (2, 3)

but it gives and error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN TestNumber = 2 THEN InactiveBitwise = (InactiveBitwise |'

Both TestNumber = 2 and 3 exist, because I have previously got them from a call to the database.

Does anyone know what it does not like?

Upvotes: 3

Views: 692

Answers (1)

Shadow
Shadow

Reputation: 34232

You need to specify what column's value you want to change and the case will determine the returned value only:

UPDATE tests SET InactiveBitwise = CASE
        WHEN TestNumber = 2 THEN (InactiveBitwise | 4)
        WHEN TestNumber = 3 THEN (InactiveBitwise | 8)
     END
WHERE TestNumber IN (2, 3)

Upvotes: 2

Related Questions