• sqlfriends (5/14/2013)


    I would like to convert a varchar column to datetime.

    The varchar column are supposed are be like a date : 2013-05-12

    But there may be a wrong date due to user error: like this one 0210-05-12.How can I use a statement to convert all them to datetime and if it is a invalid one like above, make it null.

    Thanks

    Wow! Deja vu! I believe a couple of other folks have asked this question with that very same bad date. You folks all taking the same course? 😉

    --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)