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 WHEN Help Please

Author  Topic 

Jonny1409
Posting Yak Master

133 Posts

Posted - 2008-11-10 : 03:39:36
Hello,

I'd like some help please if possible.

I have a field in my DB table called 'HolidayAllowance'.
I'd like to do a IF, THEN, ELSE Statement on this field to produce another field.

I know I'll have to use a CASE WHEN statement, but I can't work out the exact syntax I need in my situation.

Basically I want to say, IF 'HolidayAllowance' is Less that 25, set the new field to 25, otherwise set the new field to be the same as the 'HolidayAllowance' field.

Can anyone help me with the syntax please ?
Thank you in advance.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-10 : 03:42:34
UPDATE Table1
SET Col2 = CASE WHEN Col1 < 25 THEN 25 ELSE Col1 END



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Jonny1409
Posting Yak Master

133 Posts

Posted - 2008-11-10 : 05:12:46
Thanks Peso - that works a treat.

Go to Top of Page
   

- Advertisement -