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

Order by Statement

Status
Not open for further replies.

vb89

MIS
Aug 21, 2008
47
US
I have the following SQL statement
Code:
 CURSOR player_cursor IS
    select *
    from customer_data.cd_soccer_players p
    where p.team_id = tID
    and p.league_id = p_leagueID
    and p.status = 'Y';

I would like to order the following statement by a column called player_position. Player position has four different options: goalie, forward, center, defense. I would like to have the player be ordered in the following order:
1. Forward
2. Defense
3. Goalie
4. Center

Any help would be greatly appreciated
 
Hi,

Try

Code:
select *, case 
  when player_position = 'Forward' then 1
  when player_position = 'Defense' then 2	
  when player_position = 'Goalie' then 3
  when player_position = 'Center' then 4  
  end as rank
from customer_data.cd_soccer_players p
where p.team_id = tID
and p.league_id = p_leagueID
and p.status = 'Y'
order by rank asc

Ryan
 
when i try to run the statement, is says that 'FROM' is not found where expected
 
Actually, looking at your cursor definition are you working off an Oracle db?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top