Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query if ANY record between specific time Expand / Collapse
Author
Message
Posted Friday, June 07, 2013 1:19 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, March 25, 2014 4:03 PM
Points: 16, Visits: 64
So, say I have a record where StartTime is '2013-06-07 13:00:00.000' and EndTime is '2013-06-07 13:02:00.000'

Is there a way to have T-SQL select this record if I'm querying for time between StartTime and EndTime that is '2013-06-07 13:01:00.000'? Essentially I'm looking for all records where StartTime and EndTime overlap with the time I'm querying for.

I can't figure out the syntax for it, and I'm not having any luck searching for it.

Thanks for any help you can provide!
Post #1461201
Posted Friday, June 07, 2013 1:30 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 10:38 PM
Points: 22,534, Visits: 30,312
tmac25 (6/7/2013)
So, say I have a record where StartTime is '2013-06-07 13:00:00.000' and EndTime is '2013-06-07 13:02:00.000'

Is there a way to have T-SQL select this record if I'm querying for time between StartTime and EndTime that is '2013-06-07 13:01:00.000'? Essentially I'm looking for all records where StartTime and EndTime overlap with the time I'm querying for.

I can't figure out the syntax for it, and I'm not having any luck searching for it.

Thanks for any help you can provide!



...
WHERE
@SearchDateTime between StartTime and EndTime -- where StartTime and Endtime are the actual column names in the table
...





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1461205
Posted Friday, June 07, 2013 3:55 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, March 25, 2014 4:03 PM
Points: 16, Visits: 64
Lynn Pettis (6/7/2013)
tmac25 (6/7/2013)
So, say I have a record where StartTime is '2013-06-07 13:00:00.000' and EndTime is '2013-06-07 13:02:00.000'

Is there a way to have T-SQL select this record if I'm querying for time between StartTime and EndTime that is '2013-06-07 13:01:00.000'? Essentially I'm looking for all records where StartTime and EndTime overlap with the time I'm querying for.

I can't figure out the syntax for it, and I'm not having any luck searching for it.

Thanks for any help you can provide!



...
WHERE
@SearchDateTime between StartTime and EndTime -- where StartTime and Endtime are the actual column names in the table
...




I can't believe it was that simple, thank you!
Post #1461244
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse