I have researched everywhere but still can't seem to fix a simple error: Running Microsoft SQL server:
UPDATE copyprogmaster
SET active =
CASE
WHEN active = 1 THEN active = 0
WHEN active = 0 THEN active = 1
ELSE active
END
WHERE source = 'Mass_Mail'
my error is :
Line 4: Incorrect syntax near '='.
Remove the =
after the THEN
, so:
UPDATE copyprogmaster
SET active =
CASE
WHEN active = 1 THEN 0
WHEN active = 0 THEN 1
ELSE active
END
WHERE source = 'Mass_Mail'
You already have active =
after the SET
on the second line.
You do not need to repeat "active =" after THEN
UPDATE copyprogmaster
SET active =
CASE
WHEN active = 1 THEN 0
WHEN active = 0 THEN 1
ELSE active
END
WHERE source = 'Mass_Mail'
Here's an example from the documentation at http://msdn.microsoft.com/en-us/library/ms181765.aspx
USE AdventureWorks2008R2;
GO
SELECT ProductNumber, Category =
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END,
Name
FROM Production.Product
ORDER BY ProductNumber;
GO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With