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

datetime query Expand / Collapse
Author
Message
Posted Thursday, August 20, 2009 1:01 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 01, 2011 10:58 AM
Points: 76, Visits: 906
Hi,

Need some help on the query,I have some problem writing a query for starttime falling between a range

select * from table where starttime between @starttime and @endtime

if here @starttime=20/08/2009 5:00:00.000 and @endtime=20/08/2009 10:00:00.000

by applying above start and endtime i also get the records from which start after 10:00:00.000

for example i get returned records whose start time is 20/08/2009 10:00:00

to resolve this i have used the below but i think this is not better way to do

select * from table where starttime between @starttime and @starttime and
endtime between @endtime and @endtime

Please help with this


Thanks
Post #774029
Posted Thursday, August 20, 2009 1:13 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, May 10, 2013 4:07 PM
Points: 1,943, Visits: 8,227
between does greater than or equal to and less than or equal to , so from what you've said ,"returned records whose start time is 20/08/2009 10:00:00", SQL seems to be returning the right data.

Can you provide a script that emulates your issue ?





Clear Sky SQL
My Blog
Kent user group
Post #774037
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse