Flat File Date Conversion

  • hi guys

    I've got a flatfile with 2 date fields which have the ISO format of yyyymmdd

    And i'd like to import it into my db as mmddyyyy.

    The fields are fixed length with 8 bytes.

    In my package if I try to set these 2 fields to a SSIS datatypes of

    Database_Date or DT_DATE and i get an error:

    [Toll_Log [65]] Error: Data conversion failed. The data conversion for column "TransactionDate" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".

    I even tried passing it as string and then converting it to date with data convertion tool. and i get this error:

    [Data Conversion [1490]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "output column "Copy of TransactionDate" (1504)" failed because error code 0xC020907F occurred, and the error row disposition on "output column "Copy of TransactionDate" (1504)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.

    How can i convert it properly in SSIS?

    Thanks

     

     

    Alex S
  • Instead of Database_Date or DT_DATE try using DT_DBTIMESTAMP.

  • Lynn

    I get the same error.

    [TollLog [65]] Error: Data conversion failed. The data conversion for column "TransactionDate" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".

    Alex S
  • The field you are going to that you want formatted mmddyyyy, is this a date field or a character field?

  • FINALLY!!!

    Lynn i changed those columns to (DT_STR) in the flat file source and then added derived column tool.

    I got it to work by using a derived column transformation tool and by adding

    (DT_DBDATE)(SUBSTRING([TranDate],1,4) + "/" + SUBSTRING([TranDate],5,2) + "/" + SUBSTRING([TranDate],7,2))

    in the expression box.

    In the table those 2 flelds are datatime.

    Converts yyyymmdd to mm/dd/yyyy.

     

     

    Alex S
  • Curious, why are you storing dates as strings instead of as dates?

     

  • They are stored as smalldatetime in the table after SSIS processing.

    But when they come in from flat file source i have to store them in string(DT_STR) in order to successfully convert from yyyy/mm/dd to mm/dd/yyyy.

    When i tried storing them as DT_DATE, DT_DBDATE or timestamp i got errors. 

     

     

    Alex S
  • Derived column and/or data type conversion works but its slow. I made a test and it takes 9 hours longer to import 30GB file using derived column than 1 to 1 mapping and implicit conversion (i skipped date field and run test on the same machine).

    I would really like to know the way how to configure date format and use the most simple and fastest load mechanism. I would like to have source flat file and destination table only plus 1:1 transformation in between. In Oracle and even MySQL its possible. Must be also possible in IS

    A Nobel price for the one who knows the answer!!

    Tomek

  • I got the same error as well. Did you got a solution yet? thanks 😀

  • I am having the same issues. Does anyone know an efficient way to convert dates?

  • Use ISO-Formated (YYYY-MM-DD) date-fields to import.

  • The files I recieve are usually in yyyymmdd or mm/dd/yyyy form. Unless I go in a change them myself, which I am not about to do, I have to import them like this somehow.

    Everything I have tried has failed on these imports. I have tried Cast and Convert statements with no luck either.

  • The SSIS Datatype Conversion functions DT_DATE, DT_DBDATE, DT_DBTIMESTAMP don't do what people expect them to do and there is a lot of confusion in this area (no thanks in part to BOL).

    We would expect that by applying the function before a datetime value it would convert it but as the input is in string format (which it usually is when dealing with flat file sources) it is necessary to convert the string into the exact format the datatime conversion function is expecting.

    Thus you will need to use the SUBSTRING function within an expression.

    DT_DBDATE also strips out the time portion, thus expects yyyy-mmm-dd or yyyy-mm-dd, so you need to build you datetime value in string format as yyyy-mmm-dd or yyyy-mm-dd.

    For extracting both date and time use DT_DATE which expects it as dd/mmm/yyyy hh:mm:ss or dd/mm/yyyy hh:mm:ss (this format is dependent upon the locale property of the Transformation but this is the format for English(UK).

    You also need to watch out for nulls and blank spaces in the source data which will cause the transformation to fail if not accounted for in your expression.

    Paul R Williams.

  • Yea I actually posted something similar on the forums yesterday that I got resolved. Here is the code I had to use to get it to work properly.

    UPDATE temp_ameriflex_detail

    SET emp_doh = CONVERT(VARCHAR(10), CAST(emp_doh as DATETIME), 112)

    Thanks for the reply guys.

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

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