Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CASE in Update Statement

Author  Topic 

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2008-09-18 : 12:33:09
Hi Guys

IS it possible to use a CASE statement in an UPDATE statement?

i'm using the following query but it doesnt seem to work, any ideas?

UPDATE [TMP.PUDImport]
SET [Flag] = (CASE [Flag] WHEN [ForDeletion] = 0 THEN 1
WHEN [ForDeletion] = -1 THEN 2
END)

Any ideas?

Thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-09-18 : 12:37:11
Where is "Where Clause"?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 12:38:24
quote:
Originally posted by rcr69er

Hi Guys

IS it possible to use a CASE statement in an UPDATE statement?

i'm using the following query but it doesnt seem to work, any ideas?

UPDATE [TMP.PUDImport]
SET [Flag] = (CASE [Flag] WHEN [ForDeletion] = 0 THEN 1
WHEN [ForDeletion] = -1 THEN 2
END)

Any ideas?

Thanks


no need of column name after CASE
Go to Top of Page
   

- Advertisement -