Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vb89
Starting Member
9 Posts |
Posted - 2008-09-22 : 18:07:49
|
I have the following SQL statement 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. Forward2. Defense3. Goalie4. CenterAny help would be greatly appreciated |
|
|
Mapper
Starting Member
12 Posts |
Posted - 2008-09-22 : 18:16:33
|
| Use a case statement to create a new field called "OrderStatus"CASE WHEN Player-Position = "Forward Order Status = 1C W PP = "Defense"Order Status = 2Then Order on the Order Status Field.http://www.BackcountrySecrets.com - Find and share places to play outdoors |
 |
|
|
Mapper
Starting Member
12 Posts |
Posted - 2008-09-22 : 18:22:27
|
| Sorry I just read that and it made no sense.Try thisSELECT * FROM customer_data.cd_soccer_players p WHERE p.team_id = tID AND p.league_id = p_leagueID AND p.status = 'Y'ORDER BY CASE WHEN p.player_position = 'Forward' THEN 1CASE WHEN p.player_position = 'Defense' THEN 2CASE WHEN p.player_position = 'Goalie' THEN 3ELSE 4END;http://www.BackcountrySecrets.com - Find and share places to play outdoors |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 00:15:06
|
quote: Originally posted by Mapper Sorry I just read that and it made no sense.Try thisSELECT * FROM customer_data.cd_soccer_players p WHERE p.team_id = tID AND p.league_id = p_leagueID AND p.status = 'Y'ORDER BY CASE WHEN p.player_position = 'Forward' THEN 1CASE WHEN p.player_position = 'Defense' THEN 2CASE WHEN p.player_position = 'Goalie' THEN 3ELSE 4END;http://www.BackcountrySecrets.com - Find and share places to play outdoors
no need to repeat CASE keyword each time |
 |
|
|
|
|
|