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 |
|
wkcalvin
Starting Member
2 Posts |
Posted - 2012-04-10 : 23:31:11
|
| Hi I am newbie to SQL programming and using SQL Express 2008, I am writing a horse racing program with a table as belowDate Horse Stable Rank10-4-2012 ABC DS 81-4-2012 ABC DS 925-3-2012 ABC WK 1020-3-2012 ABC WK 5Now I want write a query to assign a value 1 (for example) for today’s race that HORSE ABC has CHANGED STABLE and STILL NOT WIN A RACE YETHow can I write this query?Thanks very much |
|
|
vinu.vijayan
Posting Yak Master
227 Posts |
Posted - 2012-04-11 : 01:25:56
|
From what I understood, I think you want to add a field for win/loss status based on the rank field. If I am right, then you could try this:Alter Table Horse_RaceAdd Status varchar(max)GoUpdate Horse_RaceSet Status = Case When Rank = 1 Then 'Won' Else 'Lost' EndGo Vinu Vijayan |
 |
|
|
vinu.vijayan
Posting Yak Master
227 Posts |
Posted - 2012-04-11 : 01:27:34
|
| Edit: If you want to change the value of status as '0' and '1' for win/loss. Then you can change that in the code. |
 |
|
|
wkcalvin
Starting Member
2 Posts |
Posted - 2012-04-11 : 03:45:16
|
Hi AllThe below is the table, you can see horse 74396078 change stable at 20111217 (train_uid 14160047) and still not get a win(rank 1) till now.Horse 83739599 has not change stable for allMy query is want to find out horse 74396078 in a huge table with many horses and their records. Thanks |
 |
|
|
|
|
|