Results 1 to 5 of 5

Thread: convert and isdate

  1. #1
    Join Date
    Nov 2002
    Posts
    261

    convert and isdate

    I have a text file I have to load an massage the data. There is a date field which is a varchar where I do a conversion. As of 7-19 the conversion to inline sql stoppped working. Look at example below

    declare @dob varchar(08)
    set @dob = '02291956'
    select convert(datetime,Right(@dob,4) + Left(@dob,4)) as dob
    select convert(datetime,Right(dob,4) + Left(dob,4)) as dob from marylanddoc

    The 1st statement works, however the select statement now fails with a conversion failure. ANyone seen this pop up. Just as an FYI, I do have 20 records that were processed with a leap year 0229 date that were created by this process before 7/19

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    What was the error?

  3. #3
    Join Date
    Nov 2002
    Posts
    261
    Server: Msg 242, Level 16, State 3, Line 4
    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
    I checked the table these records get inserted into, and there were previous values that were leap year dates that worked. Just stopped working Thursday.
    It looks like the conversion on the defined variable works fine, but the conversion on at the table level fails

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    Any strange value in source column?

  5. #5
    Join Date
    Nov 2002
    Posts
    261
    No and then I tried this

    declare @dob char(08)
    set @dob = '02291956'
    select isdate(convert(datetime,Right(@dob,4) + Left(@dob,4))) as dob
    select isdate(convert(datetime,Right(dob,4) + Left(dob,4))) from marylanddoc


    The isdate for the @dob returns 1, it fails when reading the char(08) field. Any other value in this char field converts, except for the leap year

Posting Permissions

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