Question

I have a large .CSV file, I tried to import it into SQL Server using Bulk Insert. A few records inserted correctly, however others are just messed up due to below reason.

    Create table Testing 
    (
     field1 varchar(10),
     field2 varchar(10),
     field3 varchar(10),
     field4 varchar(50),
     field5 varchar(10)
   )

File data

no,fname,lname,address,cellphone
1,john,demo,10th street,1234567890
2,smith,demo,park view,111111111
3,venus,demo,"POBOX,CA",222222222

Code:

BULK INSERT npidata
FROM 'C:\temp.csv'
WITH
(
   FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n'
)

First two records inserted correctly, issue with 3rd record as more than 4 commas are into 3rd row.

Please suggest how to handle this case.

Thanks in advance.

Was it helpful?

Solution

Regarding your problem, from the searching I've been doing on this, I believe that speech marks "" are a problem for imports.

You might need to write a script that processes your data and removes speech marks or extra commas before you do the import to your database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top