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

Putting a condition on an column in SQL query

Status
Not open for further replies.

ghbeers

Programmer
Jul 17, 2014
76
US
I want the field PP.POSPAY_SALARY_MIN modified depending on the value in P.POS_HRLY_OR_SLRY. Not sure the best way to do this.

select distinct
...
P.POS_HRLY_OR_SLRY,
PP.POSPAY_SALARY_MIN,
...

So the logic would be

if P.POS_HRLY_OR_SLRY = 'S' then PP.POSPAY_SALARY_MIN / 1000 else PP.POSPAY_SALARY_MIN / 10;

PP.POSPAY_SALARY_MIN is coming out of the database as a integer/character, no decimal points. If I could get the conditional statement correct I suppose I could also use a substring to remove the trailing zeros.
 
Code:
Select Distinct
...
P.POS_HRLY_OR_SLRY,
PP.POSPAY_SALARY_MIN, 
Case When P.POS_HRLY_OR_SLRY = 'S' 
     Then PP.POSPAY_SALARY_MIN / 1000.0 
     else PP.POSPAY_SALARY_MIN / 10.0
     End As YourNewColumnAliasName
...

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you. I thought I'd tried that earlier and got errors. I must have done something wrong when I tried it. Works great now. Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top