I have a table of race courses. Some races only have 1 course, while others may have >1.
The courses are closed at predetermined times so there can only be one open course at a time where the coursenumber is the lowest and the complete flag is false.
the query
declare @eventlistid int select @eventlistid = 118 Declare @Courseid int SELECT @Courseid = (Select courseid from course where eventlistid = @eventlistid, complete = 0 and coursecount = MIN(coursecount))
the table
1 113 Balltown Classic 1 FALSE 2 112 Balltown 100 1 FALSE 3 114 Metamora 100 1 FALSE 4 115 Metamora 4X50 1 FALSE 5 116 Buffalo Bills Long Loop 1 FALSE 6 116 Buffalo Bills Mid Loop 2 FALSE 10 116 Buffalo Bills Short Loop 3 FALSE 11 117 Dawn2Dusk Long 1 FALSE 12 117 Dawn2Dusk Mid 2 FALSE 13 117 Dawn2Dusk Short 3 FALSE 14 118 The 24 Long 1 FALSE 15 118 The 24 Mid 3 FALSE 16 118 THE 24 Short 3 FALSE
col 1:ID PK
col 2: the event id
col 3: the event name
col 4 the course sequence
col 5 whether the course is closed
I need the courseid for the lowest sequence loop that is false-any ideas?