Selecting records with same day and month as today

  • this should help

    select xys from mytable where datepart(dd,mytable.datefield)=datepart(dd,getdate()) and datepart(mm,mytable.datefield)=datepart(mm,getdate())

    Cheers

    MVDBA

  • Thanks, that did it!

     

    JW

  • Just for the sake of another option

    where right(convert(char(8),mytable.datefield,112),4) = right(convert(char(8),getdate(),112),4)

  • out of interest is it quicker?

    MVDBA

  • Don't know for sure. I usually just test a few options to see which gives best performance for the data in question, just make sure you run several times for comparison and clean the buffers between runs for best compare if possible.

Viewing 5 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply