all groups > sql server mseq > october 2004 >
You're in the

sql server mseq

group:

Update Question



Update Question John
10/18/2004 12:47:03 PM
sql server mseq: can you update date a column with an if then statement. This is a simple
example and I want to do something more complex, but I can't figure out how
to do this simple example. can someone help?

update car set field1 = (if (select passengers from car where id=1)='3' begin
'2'
Re: Update Question Anith Sen
10/18/2004 4:56:07 PM
You can do this using CASE in SQL like:

UPDATE Car
SET field1 = CASE passengers WHEN '3' THEN '2' END
WHERE id = 1 ;

Note that all the values for passengers that is not equal to '3' for id
value 1 will be set to NULLs since there is no ELSE clause in the CASE
expression. For more details and examples on CASE, please refer to SQL
Server Books Online.

--
Anith

AddThis Social Bookmark Button