?
Solved

SQL2000 - Two different DateTime values return equal

Posted on 2006-07-11
4
Medium Priority
?
712 Views
Last Modified: 2008-01-09
Can anyone tell me why it is that Sql Server 2000 returns 1 on the this?:

Declare @firstDate DateTime
Select @firstdate = '6/15/2006'
Select 1 where '6/14/2006 23:59:59.999' = @firstDate

These are two separate DateTime values, but yet SQL Server 2000 seems to think they are equal... This threw a reporting query of mine off simply because the statement returns true in my match criteria.
0
Comment
Question by:Sean McIlvenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 375 total points
ID: 17085719
Hi realevergod,

The datetime data type does not have the ability to resolve differences larger than 0.03 seconds, so
6/14/2006 23:59:59.999 rounds up to 6/15/2006 0:00:00

Regards,

Patrick
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 17085726
> resolve differences larger than 0.03 seconds

Sorry, meant SMALLER than :)

Regards,

Patrick
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17085733
I could reproduce your problem, I went even a step further (no solution):

Declare @firstDate DateTime
Select @firstdate = convert(datetime,'6/15/2006',101)
declare @lastdate datetime
select @lastdate = convert(datetime, '2006-06-14 23:59:59.999', 121)
Select 1 where @lastdate = @firstDate
select convert(varchar(30), @firstdate, 121), convert(varchar(30), @lastdate, 121)

Listening & Learning
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 17085739
realevergod,

Sorry, the smallest resolution is not 0.03 seconds, but rather 1/300th of a second, or about 0.00333 seconds.
But SQL Server still has to round yours up.

Regards,

Patrick
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question