sql server - Bulk insert fmt text qualifier -
i've bulk insert task takes data csv , imports table. problem 1 of columns can contain comma, import doesn't work expected.
i've tried fix creating format (fmt) file, contents of i've detailed below:-
9.0 6 1 sqlchar 0 50 "," 1 "identifier" latin1_general_ci_as 2 sqlchar 0 50 "," 2 "name" latin1_general_ci_as 3 sqlchar 0 50 "," 3 "date of birth" latin1_general_ci_as 4 sqlchar 0 50 "," 4 "admission" latin1_general_ci_as 5 sqlchar 0 50 "," 5 "code" latin1_general_ci_as 6 sqlchar 0 50 "\r\n" 6 "length" latin1_general_ci_as
the column causing me pain column 2 "name".
i've tried couple of things identify column being text qualified , containing comma i'm not getting result want.
if change following:-
"\","
- -- "richardson, mat
this isn't correct, tried instead, suggested on other forums / sites:-
"\",\""
this doesn't work @ , gives me error
cannot obtain required interface ("iid_icolumnsinfo") ole db provider "bulk" linked server "(null)".bulk load: unexpected end of file encountered in data file.
i've tried few other combinations , can't right. or guidance massively appreciated.
not answering question regarding format files possible working solution.
format files incomprehensible arcana 1980s me, bulk insert uber fussy , unforgiving. therefore tend clean data few lines of powershell instead. here's example used convert csv pipe separated, remove random quoting on output , allow commas in records:
import-csv -path $dirtycsv | convertto-csv -notype -delimiter '|' | %{ $_.replace('"','') } | out-file $cleancsv
you idea...
this imported:
bulk insert sometable 'clean.csv' ( firstrow = 2, fieldterminator = '|', rowterminator = '\n' )
hope helps.
Comments
Post a Comment