4

I am running SQL 2008, bulk insert command, while inserting the data, I am trying to remove (") double quotes from the CSV file, which works partially, but doesnt work for all the records, please check my code and the screenshot of the result.

Bulk Insert tblUsersXTemp from 'C:\FR0250Members161212_030818.csv' WITH (FIELDTERMINATOR = '","', ROWTERMINATOR = '"\n"', --FormatFile ='' ERRORFILE = 'C:\bulk_insert_BadData.txt') 

enter image description here

1
  • Are the rows that have a problem the first and last of the CSV? Commented Dec 14, 2016 at 17:50

2 Answers 2

6

After you do the bulk insert, you could replace the double quotes.

UPDATE tblUsersXTemp SET usxMembershipID = REPLACE(usxMembershipID, CHAR(34), '') 
Sign up to request clarification or add additional context in comments.

2 Comments

What does CHAR(34) signify here?
@psam the quotes
1

You need a format file I believe, that's what I think is going on.

If you use the following Bulk Insert command to import the data without using a format file, then you will land up with a quotation mark prefix to the first column value and a quotation mark suffix for the last column values and a quotation mark prefix for the first column values.

Reference

Example from reference:

BULK INSERT tblPeople FROM ‘bcp.txt’ WITH ( DATAFILETYPE=‘char’, FIELDTERMINATOR=‘","’, ROWTERMINATOR = ‘\n’, FORMATFILE = ‘bcp.fmt’); 

You could also potentially have dirty data that uses quotes for more than just delimiters.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.