Reputation: 645
I have TableA with the following data
Name A B Final
Andy 1 1 2
Sam 1 0 2
I want to write an update query which will do the following:
My Query
Update TableA
Set A = Case when Final in (1,2) then 1 else 0 End
Set B = Case When Final = 2 then 1 else 0
where final in (1,2) and **final <> sum(A+B)**
Since we can't use an aggregate function in update where clause I am not sure how to do the last part.
The query should only update row for Sam.
Thanks for you help!
Upvotes: 0
Views: 360
Reputation: 173056
Update TableA
Set A = Case when Final in (1,2) then 1 else 0 End
Set B = Case When Final = 2 then 1 else 0
where final in (1,2) and final <> A+B
Upvotes: 1