Solved

T-SQL datetime equality comparison

Posted on 2006-11-02
3
5,598 Views
Last Modified: 2012-06-21
I would like to check wethere 2 columns which are of type dateime have the same date.When I test ,I see that
table1.dateT1 = table2.date2 does not work,even though they have the same date time/ Should I have to convert to a string to do the same?
0
Comment
Question by:aswam1975
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
grant300 earned 30 total points
ID: 17858968
The problem is the precision of the date/time.  They are accurate to the nearest 1/300th of a second.  As a result, if you want to compare dates, you either have to round the dates or convert to strings with just the date and no time

Be aware, putting functions into SARGs will frequently prevent the optimizer from using available indexes.  Depending upon how much data you have and the performance requirements for this query, you may find it best to add a date field with just the pre-rounded date on at least one of the two tables.

Bill
0
 
LVL 10

Expert Comment

by:bret
ID: 17859471
A computed column or function-based index (features in 15.x) to convert the datetime to just data are good solutions
0
 
LVL 19

Expert Comment

by:grant300
ID: 17860562
Ther world will be a better place when most of us are running >=15 :-)

Bill
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Small DB [ Application with 20GB Storage Size Minimum ] 4 514
Visual Studio 2010 with SyBase 3 842
Dynamically Growing Sybase Database 3 444
sybase T-sql different 2 112
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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