Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of problems here:</p> <ol> <li><p>I suspect there isn't a valid <code>\n</code> on the first line. Otherwise SQL Server wouldn't munge the first two rows when you change to <code>FIRSTROW = 1</code>.</p></li> <li><p>Using <code>","</code> as the column delimiter works great for all of the columns except the first and the last column. This leaves a leading <code>"</code> on the first column, and a trailing <code>"</code> on the last column. You can deal with the latter by changing your <code>ROWTERMINATOR</code> to <code>"\n</code>, but that will only work if you can also add a trailing <code>"</code> to the header row (during the process of ensuring that there is a valid <code>\n</code> there). At that point you may as well make sure that the header row matches the data rows in all aspects, so:</p> <pre><code>"COLUMN1","COLUMN2" -------------------^ this character has to be \n </code></pre></li> </ol> <p>In all honesty, I think you could spend a week fighting with all of these nitty-gritty <code>BCP</code> and <code>BULK INSERT</code> issues, and still not have a perfect solution that doesn't require post-op actions (such as trimming leading/trailing <code>"</code> characters from certain columns). My recommendation: spend 20 minutes and write a parser in C# that will automatically correct these files - removing the header row, ensuring the right delimiters are in place, removing all the stupid <code>"</code>, etc. before SQL Server ever sees the file. Cleaning the file up will be a lot less hassle than the hoops you're jumping through now. I'm sure there are solutions to this but IIRC you've been wrestling with it for quite some time...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload