SSIS Excel Import Forcing Incorrect Column Type

后端 未结 16 1165
醉梦人生
醉梦人生 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条回答
  • 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.

    0 讨论(0)
  • 2020-11-30 01:48

    If multiple columns in the excel spreadsheet present with the same name, this kind of error occurs. The package will work after making the column name's distinct. Sometime the hidden columns are being ignored while checking the columnn names.

    0 讨论(0)
  • 2020-11-30 01:51

    Another workaround is to sort the spreadsheet with the character data at the top, thereby causing Excel to see the column as string, and importing everything as such.

    0 讨论(0)
  • 2020-11-30 01:53

    Well IMEX=1 did not work for me. Neither did Reynier Booysen's suggestion. (I don't know if it makes a difference but I'm using SQL Server 2008r2). A good explanation of some workarounds and also some explanations of why IMEX=1 is limited to the first eight rows of each spreadsheet can be found at http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/78b87712-8ffe-4c72-914b-f1c031ba6c75

    Hope this helps

    0 讨论(0)
提交回复
热议问题