I have an odd thing happening with importing data from Excel to SQL Server using the Import and Export Data tool.
The short of it is that I can see the data in Excel, but all of the data doesn’t import.
I have an excel workbook containing one spreadsheet. I can see the data in the columns and everything looks good. When I use the import wizard to import the data, I can see the columns and the preview data, but the data doesn’t all get transferred over when the import is executed. There are no errors and the import process finishes – it just inserts a bunch of null values into the table.
It seems to happen most with numbers – so let’s say I have three columns for first name, last name, and ID number. I’ll get all of the first and last names, and some of the ID numbers. I can’t find a pattern for what’s happening.
I had this happen once before and I noticed that there were two spreadsheets to choose from during the import process: DataImport and DataImport$ - and the first one would fail as described above and the second one would import flawlessly. This time there is only one spreadsheet to select.
I’m mainly using an XLS document and the 32-bit import wizard on a 64-bit system, but I’m willing to try anything.
Any ideas of why there are two spreadsheets (sometimes) and why this import would fail?
Dave
Its because the oledb driver "guessed" the data was numeric. Either change the definition of the column, or export it as a csv file first and use that as the import.
Copy and paste – a quick reference First, copy the data from Excel, and then paste it into the SQL Server table using the Database > Table > Edit top 200 rows menu option.
The answer to your question might involve the HOW data is stored in Excel.
I just ran into the same problem. I had a column containing two types of values: numeric and numeric with a dash. (ex. 51000 and 2009-00949) I needed to import them as either NVARCHAR or VARCHAR, but the SQL import wizard (SQL2005) would only import the numerics and not the numerics with a dash or the numerics with a dash and not the numerics, depending on which type was in the first record. The values which were not imported would have a 'null' value in the field, rendering my records useless.
I tried using the Format|Cells menu option in Excel (numeric, text, general, etc) and various mapping options in SQL (nvar, nvarchar, varchar, sqlvariant, float) without success.
The solution was to use the Data|Text To Columns option in Excel, not the cell formatting option to store the numeric value as text. When I used this on the column, the numeric values (ex. 51000) converted to numbers stored as a text value (little green triangle error appeared in the upper left corner), the numerics with a dash remained as text. I had to leave the data in this format, with the little green triangle error, otherwise it would not successfully import to SQL. When the data in the column was stored in this format, the two types of column data (numeric and numeric with a dash) imported correctly with the other record data, no null values in the column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With