| Author |
Topic |
|
coagulance
Yak Posting Veteran
78 Posts |
Posted - 2008-09-12 : 13:01:51
|
| [code]CREATE TABLE Event(StationID int NOT NULL ,Person varchar(20) NOT NULL, StartTime datetime NOT NULL, EndTime datetime NOT NULL)INSERT INTO Event (StationID,Person, StartTime, EndTime)SELECT 21, 'John', '08-02-2008 09:00', '08-02-2009 10:00' UNION ALLSELECT 11, 'Smith', '08-02-2008 09:30', '08-02-2009 10:40' UNION ALLSELECT 24, 'Karol', '08-02-2008 08:00', '08-02-2009 09:10' UNION ALLSELECT 51, 'Steve', '08-02-2008 09:00', '08-02-2009 10:00' UNION ALLSELECT 21, 'Ted', '08-02-2008 06:00', '08-02-2009 09:00' UNION ALLSELECT 31, 'Garry', '08-02-2008 07:00', '08-02-2009 09:00' [/code]The query would be to check at a given time who were availableEg:At 8/2/2008 9:01:00 AMExpected Result:21 'John'24 'Karol'51 'Steve'Thanks for your help |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-09-12 : 13:57:33
|
I believe your sample data is incorrect (You have 2009 on the end dates rather then 2008).drop table #EventCREATE TABLE #Event(StationID int NOT NULL ,Person varchar(20) NOT NULL, StartTime datetime NOT NULL, EndTime datetime NOT NULL)INSERT INTO #Event (StationID,Person, StartTime, EndTime)SELECT 21, 'John', '08-02-2008 09:00', '08-02-2008 10:00' UNION ALLSELECT 11, 'Smith', '08-02-2008 09:30', '08-02-2008 10:40' UNION ALLSELECT 24, 'Karol', '08-02-2008 08:00', '08-02-2008 09:10' UNION ALLSELECT 51, 'Steve', '08-02-2008 09:00', '08-02-2008 10:00' UNION ALLSELECT 21, 'Ted', '08-02-2008 06:00', '08-02-2008 09:00' UNION ALLSELECT 31, 'Garry', '08-02-2008 07:00', '08-02-2008 09:00' Declare @Checkdate datetimeset @Checkdate = '08-02-2008 9:01 am'select * from #Event awhere @CheckDate between a.StartTime and a.EndTime/*StationID Person StartTime EndTime----------- -------------------- ----------------------- -----------------------21 John 2008-08-02 09:00:00.000 2008-08-02 10:00:00.00024 Karol 2008-08-02 08:00:00.000 2008-08-02 09:10:00.00051 Steve 2008-08-02 09:00:00.000 2008-08-02 10:00:00.000 */ Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
|
|
|