tags:

views:

29

answers:

1

I would like to know the fastest way to compare two datetimes omiting the year. (In one of my querys it takes 55 secs becouse of this comparision)

As of now it have tried (with no difference in times):

    where datepart(d,date1)=datepart(d,date2) and datepart(m,date1)=datepart(m,date2)

    where CAST(datepart(d,date1) as varchar)+ CAST(datepart(m,date1) as varchar) =CAST(datepart(d,date2) as varchar)+ CAST(datepart(m,date2) as varchar)

    where datepart(y,date1) =datepart(y,date2)

    where CAST(DAY(date1) as varchar)+ CAST(MONTH(date1) as varchar) =CAST(DAY(date2) as varchar)+ CAST(MONTH(date2) as varchar)
A: 

Create a computed column for each date that is just the date and month (potentially as a number, e.g. 3.5 for March 5th) then index that column.

ck
Although i would have preferred to know the sql commands to make the comparison more efficient without resorting to computed columns...
ase69s