Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE and IF Statements

Status
Not open for further replies.

psychoflea

Programmer
Dec 29, 2003
12
GB
Hi

Is there such a way that you can use an IF Statement within an UPDATE Statement.
Such as:

UPDATE Table 1
IF col1>= 500
SET col1 = col1*2.5
ELSE
SET col1 = col1*1.5

Thanks
 
Try

[tt]UPDATE table1
SET col1 = Decode(Sign(499 - col1),
-1,col1 * 2.5,
col1 * 1.5);[/tt]
 
Psycho,

In addition to Lewis's excellent solution, this one also works:
Code:
UPDATE table1
set col1 = case when col1 >= 500 then col1 * 2.5 else col1 * 1.5 end;
[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 20:57 (09Jan04) GMT, 13:57 (09Jan04) Mountain Time)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top