Unfortunately both BULK INSERT
and bcp
if they find a FIELDTERMINATOR
even if it were in a text "quoted" for example "Av Lope de vega, al 1300", "CABA"
will end up interpreting it as a separator.
If a terminator character occurs within the data, it is interpreted as
to terminator, not as data, and the data after that character is
interpreted as belonging to the next field or record. Therefore,
choose your terminators carefully to make sure that they never appear
in your data.
source: link
The optimal alternative would be, as long as you have control over the process of exporting to CSV, using another less common separator, for example the pipe |
or replace when generating the commas within each field.
If you do not control the export process you are in a problem, you could eventually import the complete lines into a single field and then apply some quasi-magical logic to each row (verifying number of commas) to be able to detect the invalid comma of the invalid . For example, if the next field of the address has to be a certain list, for example, if it were, let's say Document type (eg DNI, CEDULA, etc) you could assume that the field does not actually end with the comma of "Av Lope de vega, al 1300"
but with the one just before DNI
or CEDULA
, or eventually if the next field is a numeric, you could verify by ISNUMERIC()
.