SSIS Excel Import Forcing Incorrect Column Type

后端 未结 16 1331
醉梦人生
醉梦人生 2020-11-30 01:06

I\'m trying to import a spreadsheet to our database using SSIS. For some reason SSIS wants to believe two of the columns are of type Double, when they contain character dat

16条回答
  •  萌比男神i
    2020-11-30 01:46

    I was banging my head against a wall with this issue for a while. In our environment, we consume price files from our suppliers in various formats, some of which have upward of a million records. This issue usually occurs where:

    • The rows scanned by the OLEDB driver appear to contain numbers, but do contain mixed values later on in the record set, or
    • Fields do contain only numbers, but the source has some formatted as text (usually Excel files).

    The problem is that even if you set your external input column to the desired data type, the file gets scanned every time you run the package and is dynamically changed to whatever the OLEDB driver thinks the field should be.

    Our source files typically contain field headers (text) and prices (numeric fields), which gives me an easy solution:

    First step:

    • Change your SQL statement to include the header fields. This forces SSIS to see all fields as text, including the price fields.

    For mixed fields:

    • Your initial problem is solved because your fields are now text, but you still have a header row in your output.
    • Prevent the header row from making it into your output by changing the SQL WHERE clause to exclude the header values e.g. "WHERE NOT([F4]='Price')"

    For numeric fields:

    • Using the advanced editor for the OLE DB source, set the output column for the price field (or any other numeric field) to a numeric DataType. This causes any records that contain text in these fields to fail, including the header record, but forces a conversion on numeric values saved as text.

    • Set the Error Output to ignore failures on your numeric fields.

    • Alternatively, if you still need any errors on the numeric fields redirected, remove the header row by changing the SQL WHERE clause to exclude the header values then,

    • Set the Error Output to redirect failures on this field.

    Obviously this method only works where you have header fields, but hopefully this helps some of you.

提交回复
热议问题