Case in an Update

Last Post 15 Jul 2008 11:36 PM by SQLUSA. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
PaulMcKibben
New Member
New Member

--
15 Jul 2008 07:16 PM
Is it possible to use a case statement to update the value of a field? I assume so but have not found an example.

I have a table with a gender field. It initially has a value of F, M, or NULL. I want to use a CASE statement to change the value to Female, Male, or Unknown.

Thank you
GoodFella3993
New Member
New Member

--
15 Jul 2008 08:36 PM
UPDATE YourTable
SET gender = CASE WHEN 'F' THEN 'Female'
_________________WHEN 'M' THEN 'Male'
_________________WHEN ISNULL THEN 'Unknown'
_________________ELSE gender
____________END
SQLUSA
New Member
New Member

--
15 Jul 2008 11:36 PM
I would modify the previous post the following way:

UPDATE YourTable
SET gender = CASE WHEN 'F' THEN 'Female'
_________________WHEN 'M' THEN 'Male'
_________________ELSE 'Unknown'
____________END


Kalman Toth - Database, Data Warehouse & Business Intelligence Architect
SQL Server Training, SSAS, SSIS, SSRS: http://www.sqlusa.com/
SwePeso
New Member
New Member

--
16 Jul 2008 12:00 AM
quote:

Originally posted by: SQLUSA
I would modify the previous post the following way:

UPDATE YourTable
SET gender = CASE WHEN 'F' THEN 'Female'
_________________WHEN 'M' THEN 'Male'
_________________ELSE 'Unknown'
____________END


Kalman Toth - Database, Data Warehouse & Business Intelligence Architect

This is not a valid statement.

CASE what?


You are not authorized to post a reply.

Acceptable Use Policy