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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dates in SQL server

Author  Topic 

gunja99
Starting Member

5 Posts

Posted - 2000-12-08 : 06:58:12
I am trying to write a stored procedure to return results between specific dates. I am having great problems with it, as the date is stored as a datetime value in the database. We need to store the time aswell as the date, but when searching through them, we do not get the expected results.

The query I am using is:

CREATE PROCEDURE sp_getTotalConnectionsByDate
@fromdate AS datetime,
@todate AS datetime
AS

select
count(*) AS counter
from
T13connection
WHERE
dtConnection <= @todate AND
dtConnection >= @fromdate

We are just sending through dates. Now as the date getting sent in is set to be midnight (in time), we do not get any results, where say the date time is 12/5/2000 13:30 returned.

So if I set @fromdate and @todate = 12/5/2000 then we get no results, even tho there are plenty of entries in the db of 12/5/2000!

If we set the input to @fromdate = 12/4/2000 and @todate = 12/6/2000 then we get all the results for the 5th..

I believe it is to do with the dtConnection <= @todate part of the query..

Please help!
   

- Advertisement -