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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Newbie need help on writing query

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 below

Date Horse Stable Rank
10-4-2012 ABC DS 8
1-4-2012 ABC DS 9
25-3-2012 ABC WK 10
20-3-2012 ABC WK 5

Now 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 YET

How 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_Race
Add Status varchar(max)
Go

Update Horse_Race
Set Status = Case
When Rank = 1 Then 'Won'
Else 'Lost'
End
Go


Vinu Vijayan
Go to Top of Page

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.
Go to Top of Page

wkcalvin
Starting Member

2 Posts

Posted - 2012-04-11 : 03:45:16
Hi All

The 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 all

My query is want to find out horse 74396078 in a huge table with many horses and their records.



Thanks
Go to Top of Page
   

- Advertisement -