I am trying to do a bulk insert from csv into a SQL Server database. Here is a snippet of a part of the query.
The data for this column in the CSV is in the format 123,345 with commas (it could also be null, or without any digit separator), I extract it as a string, and I am trying to replace the comma with nothing and cast it to a integer, in the format file the column is
<COLUMN SOURCE="10" NAME="abc" xsi:type="SQLVARYCHAR"/>
And the query is of the form
SELECT
CAST(REPLACE(abc, '','') AS NUMERIC) abc
FROM
OPENROWSET(BULK ''' + @myfile + ''',' +
'FORMATFILE = ''' + @fomatfile + ''',' +
'FIRSTROW = 0,' +
'ROWS_PER_BATCH =' + CAST(@size as VARCHAR(4)) + '
But I get this error
Error converting varchar to numeric
for this particular column..