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

Calculations in case statement

Status
Not open for further replies.

simma

Programmer
Sep 11, 2001
398
US
Hello,
I have a variable value.Inned something like this

Select col1,col2,@var
from...
where...

The problem is i need to calculate values for @var ,
If col2='A' then @var = col1+10%
else col2='B' then @var=col1-8%

I know I have to use case statemnt but where? In select or where.
Please advice
Thanx
 
Select
col1,
col2,
(case when col2 = 'A' then col1 + col1 * .10
when col2 = 'B' then col1 + col1 * (-.08)
else col1) as var

from...
where...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top