DrakeMurdoch
DrakeMurdoch

Reputation: 859

SQL Server string to int error when importing CSV

I am trying to import a csv file into SQL Server 2017 using bulk insert. Most of the int columns, except the primary key have NULLs (as blanks in the csv file) but when I import I get an error that it can't convert a string to type int for the specified target column. Since I don't know which column it is affected, I went and replaced all the blanks with 0s, but I still get the game error.

Here is what I get after I import:enter image description here

I don't know what to do to make this work, but it doesn't seem to make sense to me.

Upvotes: 1

Views: 4293

Answers (1)

Edward
Edward

Reputation: 772

The issue is not the NULLs. There is a column in your CSV that your are expecting to contain only integer values, but it in fact contains string values that cannot be converted to integers.

Here would be an example:

my_str_to_int_col
     1.0 
     2.0 
     3.O
     4.0 
     5.0 
     ... 

Notice that 3.O should actually be 3.0

So you need to determine which column you are converting to an integer contains non-integer values.

Upvotes: 1

Related Questions