tsqln00b
tsqln00b

Reputation: 355

Using Import wizard to import Excel data into table in SQL Server 2012 failing - text truncation

I have an Excel file that I import weekly into a table.

I am using Excel 2010 and SSMS 2012. The import failed this week and I have been unable to determine why. I was able to successfully import the data into a new table. The table definitions of the new table match the ones of my old table, so that does not seem to be the issue. Below is a screen shot of the error I receive. I have checked the PO header text field and there is nothing that exceeds the datatype of varchar(255) that I have it as.

Also, I sorted the data just to see if a certain row was causing the issue and more data did insert, but I still got the error and it was not on the same row as the original import attempt. I even dropped and created the original table again and I still receive the error.

enter image description here

Upvotes: 1

Views: 1914

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175556

The problem is probably the way how Import/Export Wizard or SSIS get metadata about datatypes.

It uses first few rows. If there is a long string (longer than 255) then datatype is memo, otherwise is string.

One workaround is to sort Excel rows based on length on text column descending.

From Excel Source

Truncated text.

When the driver determines that an Excel column contains text data, the driver selects the data type (string or memo) based on the longest value that it samples. If the driver does not discover any values longer than 255 characters in the rows that it samples, it treats the column as a 255-character string column instead of a memo column.

Therefore, values longer than 255 characters may be truncated To import data from a memo column without truncation, you must make sure that the memo column in at least one of the sampled rows contains a value longer than 255 characters, or you must increase the number of rows sampled by the driver to include such a row.

You can increase the number of rows sampled by increasing the value of TypeGuessRows under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel registry key. For more information, see PRB: Transfer of Data from Jet 4.0 OLEDB Source Fails w/ Error.

Upvotes: 2

Related Questions