Bulk insert .csv - fieldterminator

sql sqlbulkcopy

Question

I have .csv which content is like this

"aa839","340000","2350444"

When I do the BULK INSERT, I use FIELDTERMINATOR = ',' Thus, the data has quote ".

I want to remove the quote ", so that my database has only aa839, 340000, 2350444.

Accepted Answer

Dont bother about replacing while doing bulk insert , you can replace later after bulk insert . So do bulk insert as it is originally and later fire update query as below. This is the fastest way too

update table set field= REPLACE(field, 'search', 'replace');

where search is "" and replace is blank


Popular Answer

here's how to do it with powershell:

Get-Content inputfilename | 
Foreach-Object {$_ -replace '\"', ''} | 
Set-Content outputfilename



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why