Sql Server - Bulk Insert - Fieldquote Does Not Recognize Double Quote

Sql Server - Bulk Insert - Fieldquote Does Not Recognize Double Quote

I'm trying to BULK INSERT a CSV table. Some of the fields have values like this: "Smith, John" Because the comma is in the 'field' - it's 'delimiting' and placing 'John' in the next column.

Here's a sample table

CREATE TABLE [dbo].[Test_CSV](
    [a] [int] NULL,
    [b] [varchar](50) NULL,
    [c] [varchar](50) NULL,
    [d] [varchar](50) NULL
) ON [PRIMARY]
GO

Here's a sample CSV file:

2,"2","Mary Smith ","Ms."
1,"1","Smith, John","Mr."

Here's the command I'm using

BULK INSERT Test_CSV FROM  'C:\MyCSV.csv' with (  FIELDQUOTE='"', FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )

Here's the data, which is WRONG, I get '

Notice column d containing ' John","Mr."

What is the correct command? thx in advance

4

1 Answer

Try

BULK INSERT Test_CSV
FROM  'C:\MyCSV.csv' 
WITH ( FORMAT='CSV');
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.