DFCRJ
asked on
Using CASE in the UPDATE statement
Could someone please tell me what I'm doing wrong please. I have tried it so many ways.
I just want to update one column based on the value held in another column.
Here's what I've tried, or one of the ways I've tried.
UPDATE Customers
SET CustTypeDescription = CASE
WHEN (CustType = 2) THEN CustTypeDescription = 'Other Retail'
WHEN (CustType = 4) THEN CustTypeDescription = 'Convenience Store'
end
and this
UPDATE Customers
SET CustTypeDescription = CustTypeDescription
CASE
WHEN CustType = 2 THEN CustTypeDescription = 'Other Retail'
WHEN CustType = 4 THEN CustTypeDescription = 'Convenience Store'
end
thanks for the help...
I just want to update one column based on the value held in another column.
Here's what I've tried, or one of the ways I've tried.
UPDATE Customers
SET CustTypeDescription = CASE
WHEN (CustType = 2) THEN CustTypeDescription = 'Other Retail'
WHEN (CustType = 4) THEN CustTypeDescription = 'Convenience Store'
end
and this
UPDATE Customers
SET CustTypeDescription = CustTypeDescription
CASE
WHEN CustType = 2 THEN CustTypeDescription = 'Other Retail'
WHEN CustType = 4 THEN CustTypeDescription = 'Convenience Store'
end
thanks for the help...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
awesome.. thanks for the help..
The ELSE was all i was missing...
UPDATE Customers
SET CustTypeDescription =
CASE
WHEN (CustType = 2) THEN 'Other Retail'
WHEN (CustType = 4) THEN 'Convenience Store'
ELSE ''
end
The ELSE was all i was missing...
UPDATE Customers
SET CustTypeDescription =
CASE
WHEN (CustType = 2) THEN 'Other Retail'
WHEN (CustType = 4) THEN 'Convenience Store'
ELSE ''
end
try:
UPDATE Customers
SET CustTypeDescription = CASE CustType WHEN 2 THEN 'Other Retail'
WHEN 4 THEN CustTypeDescription = 'Convenience Store' END
-- Use CASE in the UPDATE statement.
3>
4> UPDATE project SET budget = CASE
5> WHEN budget > 0 and budget < 100000 THEN budget* 1.2
6> WHEN budget > = 100000 and budget < 200000 THEN budget* 1.1
7> ELSE budget* 1.05
8> END