Premise: I have a monster of a .csv with lots of balance sheet information that I need to import into Microsoft SQL Server 2016 using the Import/Export Wizard. I cannot use any other import method. I need to have some columns with numbers in a numeric data type, but cannot go through the hundreds of columns with balance sheet information to set data types individually. I do not have access to the SQL Server installation folder to mess with Data Type Mapping.
I used the Suggest Types function in the Data Source section of the Import Wizard under Advanced with the following parameters:
I also tried it with the two smallest type options unchecked.
One of the columns TOTAL_SALES with numbers in it gets detected as Data Type float [DT_R4]
. Some example values in that column in the raw .csv file are:
.0000
48796000.0000
1813535000.0000
I continue in the Import Wizard and select my SQL server and the Destination Table I want to create. In the Edit Mappings menu I see the column will be created with Data Type real
. In the bottom of the window it clearly states Source column: TOTAL_SALES float [DT_R4]
.
I click OK, Next and get to the Review Data Type Mapping section. The TOTAL_SALES column has a green checkmark and it says Source Type float [DT_R4]
and Destination Type real
. OnError and OnTruncation are empty. I set the Global OnError and OnTruncation events to Ignore.
I finish the Import Wizard and get the following Error:
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "TOTAL_SALES" returned status value 2 and status text "The value could not be converted because of a potential loss of data.". (SQL Server Import and Export Wizard)
I tried opening the .csv in Excel and saving it as .xlsx while also setting the TOTAL_SALES data type to number
. Doesn't help either, as in the Wizard the Source Type is now VarChar
, Destination Type is recognised as real
, I get yellow warning signs and import of course fails with the same error.
I don't know why the Import Wizard uses real
or why conversion between float
and real
(which is just float(24)
according to MSDN anyway) is associated with data loss. Looking at the column it looks like it's always stored with 4 decimal places, so dec(something.4)
should also be a data type that the Wizard could use.
How can I import this column using an automated solution?
User contributions licensed under CC BY-SA 3.0