convert nvarchar(50) to datetime........Arithmetic overflow error

  • Hello,

    I'm trying to convert nvarchar(50) field to datetime.

    For example,

    select convert(datetime, '06/04/2008 00:00:00')

    works......

    but when I try and interrogate the nvarchar field in a table I'm getting an

    'Arithmetic overflow error converting expression to data type datetime.' error.

    My code:

    select convert(datetime, columnname)

    from tablename

    .......the column allows nulls and was wondering whether this is the cause of the error. I believe I'm missing something obvious here and would appreciate some help!

    Thanks in advance.

    Dom

  • I think i've figured it out........

    SET DATEFORMAT dmy

    Select CASE

    WHEN columnname IS NULL THEN NULL

    ELSE convert(datetime, columnname)

    END

    from tablename

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

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