• John Mitchell-245523 (7/22/2013)


    You have a date stored as varchar or similar and you want to check it's a valid date?

    Two options - the first being vastly more preferable:

    (1) Don't store dates as varchar. Use one of the date data types.

    (2) Use CONVERT to convert it to date. If it fails, you don't have a valid date. Use the TRY...CATCH syntax to trap errors.

    John

    ISDATE() is useful for this too.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden