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!

case statement syntax help

Status
Not open for further replies.

BHScripter

Technical User
Aug 26, 2002
159
US
Hello:
I know I must have my syntax wrong somewhere on this case statement but I can't see it. What's wrong with this?

case when left(o2.org_name,3)= 'DEN' then o2.org_name
when left(o2.org_name,3)= 'LAX' then o2.org_name
when left(o2.org_name,3)= 'PHX' then o2.org_name
when left(o2.org_name,3)= 'SAC' then o2.org_name
when left(o2.org_name,3)= 'SAN' then o2.org_name
when left(o2.org_name,3)='SFO' then o2.org_name
when left(o2.org_name,3)= 'PNW' then o2.org_name
else 'Corporate' hrname end

Thanks for any help as I believe my brain is melting down.
 
[tt][blue]
case when left(o2.org_name,3)= 'DEN' then o2.org_name
when left(o2.org_name,3)= 'LAX' then o2.org_name
when left(o2.org_name,3)= 'PHX' then o2.org_name
when left(o2.org_name,3)= 'SAC' then o2.org_name
when left(o2.org_name,3)= 'SAN' then o2.org_name
when left(o2.org_name,3)='SFO' then o2.org_name
when left(o2.org_name,3)= 'PNW' then o2.org_name
else [!]'Corporate' hrname [/!]end
[/blue][/tt]

I'm guessing that one of those should be the column alias.

Code:
case when left(o2.org_name,3)= 'DEN' then o2.org_name
    when left(o2.org_name,3)= 'LAX' then o2.org_name
    when left(o2.org_name,3)= 'PHX' then o2.org_name
    when left(o2.org_name,3)= 'SAC' then o2.org_name
    when left(o2.org_name,3)= 'SAN' then o2.org_name
    when left(o2.org_name,3)='SFO' then o2.org_name
    when left(o2.org_name,3)= 'PNW' then o2.org_name
    else 'Corporate' end hrname

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
In addition, why not simplify this?
Code:
case when left(o2.org_Name,3) IN ('DEN','LAX','PHX','SAC','SAN','SFO','PNW') then o2.Org_Name
else 'Corporate' end as HrName

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top