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 |
|
krugg
Starting Member
12 Posts |
Posted - 2005-03-28 : 07:35:13
|
| Hi, I am looping through some records in T-SQL using a cursor and I'm wondering if I can do a comparison for two int values. I've written down what I want to achieve inside pseudocode comments below. Is this possible or is there a better way to do it?DECLARE games_cursor CURSOR FORselect home_team_id, away_team_id, home_team_score, away_team_score from games where week_id = 2OPEN games_cursorFETCH NEXT FROM games_cursorWHILE @@FETCH_STATUS = 0BEGIN FETCH NEXT FROM games_cursor 'start of pseudocode declare @winning_team_id int if home_team_score > away_team_score set @winning_team_id = home_team_id else set @winning_team_id = away_team_id 'end of pseudocodeCLOSE games_cursorDEALLOCATE games_cursorThanksAndrew |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-03-28 : 07:47:36
|
| Select case home_team_score > away_team_score then home_team_id else away_team_id end from games where week_id=2MadhivananFailing to plan is Planning to fail |
 |
|
|
krugg
Starting Member
12 Posts |
Posted - 2005-03-28 : 22:07:58
|
| I have tried and several variants of this but I get the following error:Incorrect syntax near '>'.Any other ideas?Andrew |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-03-28 : 22:22:34
|
| you left out whenSelect case when home_team_score > away_team_score then home_team_id else away_team_id end from games where week_id=2--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
krugg
Starting Member
12 Posts |
Posted - 2005-03-28 : 22:44:50
|
| Thanks everyone I got it now... |
 |
|
|
|
|
|