I am trying to bulk insert from a csv
file to a SQL table. However, one of my columns contains numbers with scientific notation, e.g. 3E-4
. Let's name this column Column X.
I first tried creating a table with
numeric(18,9)
type for Column X, but when I try to bulk insert data to the table, I hit a type mismatch error for Column X.As this post suggested, I tried the following alternative solution: I created another table where the columns are of
varchar(255)
type instead. No problem with the bulk insert in this case. But after the data insert, I tried to alter the column type for Column X fromvarchar(255)
tofloat
. This gives me the errorError converting datatype varchar to float
.
I am not sure how to deal with this problem. The Microsoft website suggests the following : "To work around this behavior, use a format file to bulk import scientific notation float data into a decimal column. In the format file, explicitly describe the column as real or float data. "
I have no idea how to create format files. Is this the only way of working around this problem? If so, could anybody please help with the use of a format file, or instead provide an alternative solution?
Thank you!