Bulk insert into SQL Server a CSV with line breaks in fields -


I have a CSV that looks like this:

  "blah", " Blah,  

Is it possible to import? Is it directly in SQL Server?

Every line in your file ends with the new line (\ n), but you want to end the actual lines with the quotation marks and the new line. Set the ROWTERMINATOR in the bulk INSERT command :

  ROWTERMINATOR = '"\ n'  

Edit: < / Strong> I think the big problem will be with comma in the text. SQL Server does not use text inclusion. Therefore, the row will be divided into commas without checking if commas are in quotes or not.

You can do this:

  with bulk INSERT from FROM 'c: \ file.txt' (FIELDTERMINATOR = '",', ROWTERMINATOR = '" \ N ')  

This will give you the following results:

  col1 | Col2 | Col3 ---------------------------- --------------------- --------------- "Blast |" Blah, Blah, Blah Act, Act. "Column 3" Foo | "Foo, Bar, More Than One More Line." Another Column 3  

You just have to get rid of quotation marks at the beginning of each cell.

For example:

UpdateTable SET col1 = Wright (col1, len (col1) -1), col2 = right (col2, len (col2) -1 ), Col3 = right (col3, len (col3) -1)

I think you can do that too


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -