From DATETIME to SMALLDATETIME

  • Hi,

    I have query:

    select case

    when

    CAST(DATEADD(....) AS SMALLDATETIME)

    ..........

    It does not always work. Sometimes, I got following error:

    "The conversion from datetime data type to smalldatetime data type resulted in a smalldatetime overflow error."

    Is there a better way to convert? Thanks.

    Chris

  • hi,

    the range for smalldatetime is January 1, 1900 through June 6, 2079. if your dates are out of this range then this may be what is causing this error.

    HTH

    Paul

  • Thanks Paul.

    I tried to convert Julian date (non-standard, JDE OneWorld format) to SQL smalldatetime. The conversion formular required to use DATEADD function which change Julian date CHAR(6) to DATETIME format. Say, if there is a problem with data itself. Is there safe guard I could use to prevent the error?

    Chris

  • check the ISDATE function in BOL

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 4 posts - 1 through 3 (of 3 total)

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