Note that there are some explanatory texts on larger screens.

plurals
  1. POfirst data row skipped in import
    primarykey
    data
    text
    <p>I'm using a XML format file to import a CSV file, and the first data row is getting skipped. I can't figure out why.</p> <p><strong>Format file</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;RECORD&gt; &lt;FIELD ID="1" xsi:type="CharTerm" TERMINATOR='","' /&gt; &lt;FIELD ID="2" xsi:type="CharTerm" TERMINATOR='\n' /&gt; &lt;/RECORD&gt; &lt;ROW&gt; &lt;COLUMN SOURCE="1" NAME="COLUMN1" xsi:type="SQLVARYCHAR" /&gt; &lt;COLUMN SOURCE="2" NAME="COLUMN2" xsi:type="SQLVARYCHAR" /&gt; &lt;/ROW&gt; &lt;/BCPFORMAT&gt; </code></pre> <p><strong>CSV</strong></p> <pre><code>COLUMN1,COLUMN2 "ABC","ABC123456" "TNT","TNT123456" </code></pre> <p><strong>Query</strong></p> <pre><code>SELECT * FROM OPENROWSET(BULK 'C:\sample.csv', FORMATFILE='C:\sample.xml', FIRSTROW = 2) AS a </code></pre> <p><strong>Result</strong></p> <pre><code>COLUMN1 COLUMN2 ------- ---------- "TNT TNT123456" (1 row(s) affected) </code></pre> <p>If <code>FIRSTROW</code> is changed to <code>1</code>, the result becomes:</p> <pre><code>COLUMN1 COLUMN2 --------------------- ---------- COLUMN1,COLUMN2 "ABC ABC123456" "TNT TNT123456" </code></pre> <p>If the header row is removed from the CSV and <code>FIRSTROW</code> is changed to <code>1</code>, the result returns as expected:</p> <pre><code>COLUMN1 COLUMN2 ------- ---------- "ABC ABC123456" "TNT TNT123456" </code></pre> <p>Since this is an automated report that is delivered with headers, are there any other options to remedy this?</p>
    singulars
    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.
 

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