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 1234»»»

DateTime Precision Expand / Collapse
Author
Message
Posted Saturday, November 26, 2011 5:04 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Saturday, June 14, 2014 5:28 PM
Points: 341, Visits: 200
Comments posted to this topic are about the item DateTime Precision


Post #1212159
Posted Saturday, November 26, 2011 5:08 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:29 PM
Points: 5,571, Visits: 24,786
As Sherlock Holmes said to Dr. Watson ................ Very interesting

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1212160
Posted Sunday, November 27, 2011 7:07 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 9:56 PM
Points: 2,270, Visits: 3,781
Good observation. Thanks.

Mohammed Moinudheen
Post #1212195
Posted Sunday, November 27, 2011 6:49 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354, Visits: 1,299
Don't you hate it when the explanation says, "Despite what BOL says..."

It should either be mentioned in BOL or do what the BOL says.
Post #1212251
Posted Sunday, November 27, 2011 9:33 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:29 PM
Points: 5,571, Visits: 24,786
cengland0 (11/27/2011)
Don't you hate it when the explanation says, "Despite what BOL says..."

It should either be mentioned in BOL or do what the BOL says.


Heck no one is perfect, and if memory serves me correctly those who write the explanations for BOL are NOT the developers or actual personnel writing the code ...


If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1212264
Posted Sunday, November 27, 2011 9:35 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 7:15 PM
Points: 1,622, Visits: 292
The question is not really about datetime precision, but string comparison.

If the comparison value had been declared as datetime, then the other values would be implicitly converted to datetime as well and the statement would return Yes.

declare @d as datetime
set @d = '2011-07-31 00:00:00.000'
IF @d BETWEEN '2011-07-01' and '2011-07-31'
PRINT 'Yes'
ELSE
PRINT 'No'


The question as it stands could just as well have been this

if ('abcd' between 'ab' and 'abc')
print 'yes'
else
print 'no'
Post #1212266
Posted Sunday, November 27, 2011 9:41 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, May 9, 2014 12:47 AM
Points: 3,448, Visits: 4,407
Nice tricky question with stupid 'explanation'.
Of course, the string (not datetime) '2011-07-31 00:00:00.000' is greater than the other string '2011-07-31', and thus the result of the batch is 'No'.
Post #1212267
Posted Sunday, November 27, 2011 10:41 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:08 AM
Points: 860, Visits: 807
Glad I checked out the comments after getting this one wrong. I hate learning things that aren't true.


-- Stephen Cook
Post #1212277
Posted Sunday, November 27, 2011 11:31 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:49 PM
Points: 13,283, Visits: 10,156
Silly trick question...



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1212285
Posted Monday, November 28, 2011 12:46 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, July 3, 2014 2:45 AM
Points: 2,531, Visits: 536
Jostein Saethern (11/27/2011)
The question is not really about datetime precision, but string comparison.

If the comparison value had been declared as datetime, then the other values would be implicitly converted to datetime as well and the statement would return Yes.

declare @d as datetime
set @d = '2011-07-31 00:00:00.000'
IF @d BETWEEN '2011-07-01' and '2011-07-31'
PRINT 'Yes'
ELSE
PRINT 'No'


The question as it stands could just as well have been this

if ('abcd' between 'ab' and 'abc')
print 'yes'
else
print 'no'


You are right, I'ts very obvious when you think about it, but when you see something that looks like a date, you assume that SQL server see it as a date. BUT it would be dangerous if SQL server would interpret the datatypes based on the values, and this is just another reason to dislike the implicit conversions. (I know, there is no implicit conversion in the question, but we have learned to live with them so long that we assume it takes place all the time).

I really would like a database setting, a trace flag or something that warn you or prevent you from using implicit conversion and force you to use explicit conversion. Because if you do, you know that you are doing something wrong (from a performance perspective).

The explanation is not correct and should be changed.


/Håkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
Post #1212308
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse