November 6, 2007 at 7:27 pm
if i am comparing two columns (datetime values) in separate tables? is there a single function to use?
instead of saying
WHERE
datepart(day,table1.timestamp1) = datepart(day, table2.timestamp2)
AND
datepart(month,table1.timestamp1) = datepart(month, table2.timestamp2)
AND
datepart(year,table1.timestamp1) = datepart(year, table2.timestamp2)
-Thank you all
November 6, 2007 at 8:13 pm
Do you mean that you need to drop the time before you compare? If so...
WHERE DATEDIFF(dd,Table1.TimeStamp1) = DATEDIFF(dd,Table2.TimeStamp2)
Do be aware that because you have column names in formulas, there will be no chance of an INDEX SEEK... that may not be a problem, but you need to be aware of that.
On such tables, I'll normally add a calculated column to do the dirty deed of stripping the time for me... just gotta make sure it's determinant so you can use it in an Index.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply