Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    1

    Unanswered: how to catch date conversion error

    hi,

    I try to write a function which includes a statement:

    SELECT @dateReturn = CAST(@dateString As datetime)

    to convert a string to datetime.

    When it runs, sometime it will generate :
    "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."
    and all related are terminated.

    Can I find a way to catch this error and don't let it terminate the whole thing? For
    example, when this happens, I want to get datetime as NULL instead of just being
    terminated.

    Thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Check into the ISDATE() function, which you can use to conditionally exclude strings which cannot be converted to valid datetime values.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •