Another date question

  • 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

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 2 (of 2 total)

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