I have data in the csv file similar to this:
Name,Age,Location,Score "Bob, B",34,Boston,0 "Mike, M",76,Miami,678 "Rachel, R",17,Richmond,"1,234"
While trying to BULK INSERT this data into a SQL Server table, I encountered two problems.
- If I use FIELDTERMINATOR=',' then it splits the first (and sometimes the last) column
- The last column is an integer column but it has quotes and comma thousand separator whenever the number is greater than 1000
Is there a way to import this data (using XML Format File or whatever) without manually parsing the csv file first?
I appreciate any help. Thanks.
"
for the data. I don't think there is any way to do that usingbulk insert
in t-sql. You're best bet might be to preprocess the file and change the delimiter to something else (using a regex tool for instance), or import every row as is (without splitting), and split it after importing.BULK INSERT
cannot do this (outside of inserting the whole line and parsing within SQL), there are many ways such as @Borat's DTSWizard that will. With a data format like that, all be somewhat complex to get working.