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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An if statement within the colums selection part of a select statement 2

Status
Not open for further replies.

Logmaster

Technical User
Jan 2, 2006
31
US
Hi,

I am trying the write a query which will include 2 columns from a table and an additional calculation which will be based on the 2 first columns. If the 2nd column is more than two times bigger than the first column, return he 2nd column multiplied by 2, otherwise, return the 2nd column multiplied by 1.5. Does anyone know how to do something like that?

select column1,column2, If (column1>column2*2) column2*2 else column2*1.5
from table 1

Regards,
Joe
 
Code:
[COLOR=blue]select[/color] column1,column2, 
       [COLOR=blue]Case[/color] [COLOR=blue]When[/color] column1>column2*2
            [COLOR=blue]Then[/color] column2*2 
            [COLOR=blue]else[/color] column2*1.5
            [COLOR=blue]End[/color] [COLOR=blue]As[/color] [SomeColumnAlias]
[COLOR=blue]from[/color] table1

-George

"the screen with the little boxes in the window." - Moron
 
WOW, THAT WAS FAST.

GUYS, YOU ARE AWESOME!!!
 
Logmaster,

This forum is designed to reward people who help by others awarding purple stars to them. Click on the links above, "Thank xxxxx for this valuable post!" to do that.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
Hi,

I did click on the "Thank SQLDenis
for this valuable post!" and " Thank ESquared
for this valuable post!" right before I posed my last reply. I am going to do it again however if it doesn't show up this time, there is something wrong.
 
My mistake, I forgot to click on the confirmation link...
 
I don't need any stars... thank you though :)

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top