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)
 between statment error

Author  Topic 

neuromystical
Starting Member

2 Posts

Posted - 2006-05-24 : 12:07:51
SELECT * FROM PROD
WHERE EVENT_DATE BETWEEN '2006-05-15 00:00:00' AND '2006-05-15 23:59:59'

Produces results that show the date 2006-05-15 as well as the 2006-05-16 and I have no idea why this would be. If I change the '2006-05-15 23:59:29' it produces correct results. Now I know I could rewrite this with a greaterThanOrEqualTo than combined with a AND with a lessThan, however I am stumped on the why this between statement is producing results with the day I ask for as well as the day after.

Any answer to this would be appreciated or at least a step in the right direction. Am I doing something wrong or is this a bug, I am truly hoping I am doing soemthing wrong, but I do not see how.

Thanks

EVENT_DATE is in 'SMALLDATETIME'

nr
SQLTeam MVY

12543 Posts

Posted - 2006-05-24 : 12:14:27
It's probably because EVENT_DATE is a smalldatetime so it is rounding '2006-05-15 23:59:59' to the nearest minute which is '2006-05-16'

WHERE EVENT_DATE >= '2006-05-15 00:00:00'
AND EVENT_DATE < '2006-05-16'

should work.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

neuromystical
Starting Member

2 Posts

Posted - 2006-05-24 : 12:17:51
Thank you, that helps greatly!!!
Go to Top of Page
   

- Advertisement -