T-SQL datetime equality comparison

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?
aswam1975Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
grant300Connect With a Mentor Commented:
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
 
bretCommented:
A computed column or function-based index (features in 15.x) to convert the datetime to just data are good solutions
0
 
grant300Commented:
Ther world will be a better place when most of us are running >=15 :-)

Bill
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.