0

I have a set of quoted CSV files, which I need to import into SQL Server. Files look like this:

"ColA","ColB","ColC"
"12345","John Smith","-75.33"
"12356","Jane Doe","43.12"

BCP and BULK INSERT commands do not work because SQL Server cannot handle quoted fields.

How can I import files such as above?

2
  • 2
    Not true. Both BULK INSERT and BCP support format files. Commented Nov 3, 2015 at 13:45
  • Yes, but suggested answer does not require format files.
    – Serge
    Commented Nov 5, 2015 at 1:09

1 Answer 1

1

OPENROWSET command and Microsoft Access Text Driver (*.txt, *.csv) driver come to the rescue:

SELECT *
FROM OPENROWSET('MSDASQL',
'DRIVER={Microsoft Access Text Driver (*.txt, *.csv)};
DefaultDir=D:\CSV file directory;
Format=CSVDelimited;
CharacterSet=ANSI;
',
'SELECT *
FROM [filename.csv]')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.