Link to home
Start Free TrialLog in
Avatar of stonehage
stonehage

asked on

Loss of data from Excel to SQL via DTS

I have an excel spreadsheet containing SEDOL numbers. Recently the Stock Exchange began to issue them with letters as well as numbers. I am importing these, via a DTS package into a SQL table. An example is below:

0176658
2125568
DW04464
D044558

When the import is done I find that all those beginning with a letter are NULL and all those beginning with a number succeed. My column is VARCHAR. I have tried converting the column to text. I have also tried making the first line in the spreadsheet DW04464 so that DTS knows it is a mix of number and letters. Whatever I try these items do not import. Do you know of anything else I can do to avoid the loss of this data?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

This is a problem of the DTS reading the Excel with "estimating" the data type using the first (x) rows only.
As the rows start with numerical data, it will assume numerical all the time, and put NULL when it find non-numerical data.
I will try to find back the article that describes how to solve this...
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q257/8/19.asp&NoWebContent=1

Considerations That Apply to Both OLE DB Providers
A Caution about Mixed Data Types

As stated previously, ADO must guess at the data type for each column in your Excel worksheet or range. (This is not affected by Excel cell formatting settings.) A serious problem can arise if you have numeric values mixed with text values in the same column. Both the Jet and the ODBC Provider return the data of the majority type, but return NULL (empty) values for the minority data type. If the two types are equally mixed in the column, the provider chooses numeric over text.

For example:
•    In your eight (8) scanned rows, if the column contains five (5) numeric values and three (3) text values, the provider returns five (5) numbers and three (3) null values.
•    In your eight (8) scanned rows, if the column contains three (3) numeric values and five (5) text values, the provider returns three (3) null values and five (5) text values.
•    In your eight (8) scanned rows, if the column contains four (4) numeric values and four (4) text values, the provider returns four (4) numbers and four (4) null values.
As a result, if your column contains mixed values, your only recourse is to store numeric values in that column as text, and to convert them back to numbers when needed in the client application by using the Visual Basic VAL function or an equivalent.

To work around this problem for read-only data, enable Import Mode by using the setting "IMEX=1" in the Extended Properties section of the connection string. This enforces the ImportMixedTypes=Text registry setting. However, note that updates may give unexpected results in this mode. For additional information about this setting, click the article number below to view the article in the Microsoft Knowledge Base:
194124 (http://support.microsoft.com/kb/194124/EN-US/) PRB: Excel Values Returned as NULL Using DAO OpenRecordset

http://support.microsoft.com/kb/194124/EN-US/
Avatar of mvanitha
mvanitha

create a tempory table in sql server and insert the contents from excel to this temporary table

field type should be varchar()

after this

the next transformation should be from this temporary file to your table. It will work
Avatar of stonehage

ASKER

Thanks but I want the whole package to run via DTS so the import to the temporary table will include the nulls also.
did you try out my comment?
angelIII. I will try this today.
Okay. I tried very hard to do as you suggsested, resetting the connection string, but could not find enough information on how to do it. I am a novice with DTS and was unable to do this. If you have the time you may wish to explain how it can be done. To resolve the issue though I created a simple macro to run on the excel spreadshhet which places all SEDOL number containing a letter into a second worksheet and then running two separate transformations in one DTS package.
Thanks
Roger
ASKER CERTIFIED SOLUTION
Avatar of trx_1
trx_1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial