Solved

SQL2000 - Two different DateTime values return equal

Posted on 2006-07-11
4
664 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:realevergod
  • 3
4 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 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 92

Expert Comment

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

Sorry, meant SMALLER than :)

Regards,

Patrick
0
 
LVL 142

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 92

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 SQL - Query Missing Value 10 65
Compare and update data between two databases 6 58
SQL Query 34 80
Session that filled up my transaction logs 1 39
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now