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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2011-05-06 : 02:09:21
|
| I have a table that has starttime and endtime as varchar fieldsso it could be for exmaple08:00 18:00or 18:00 end time 08:00how can I query by passing in a time and checking if it's between the start and the end and if the time is 18:00 - 08:00 then 07:00 should be counted as ok but 09:00 should not. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-05-06 : 05:58:15
|
[code]declare @Sample table(txt varchar(255),Starttime varchar(10),Endtime varchar(10))insert @Sampleselect 'A','06:00','18:00' union allselect 'B','09:00','15:00' union allselect 'C','18:00','07:00'declare @Searchtime timeset @Searchtime = '19:45'select * from @Samplewhere(datediff(second,Starttime,Endtime) >= 0 and @Searchtime between Starttime and Endtime)or(datediff(second,Starttime,Endtime) <= 0 and (@Searchtime >= Starttime or @Searchtime <= Endtime))[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|