title: bulk insert skip last row
body: <p>I am doing a bulk insert that I have to skip the last row. Otherwise , I got an error saying "Bulk Insert: Unexpected end-of-file (EOF) encountered in data file."
  If I set ROWTERMINATOR='\r\n', then I got 0 rows imported.</p>
  
  <p>I wonder if there is any code that can help me skip the lastrow of the txt file? (The last row is dynamic.) My company currently doesn't have SSIS installed.</p>
  
  <p>My code for bulk insert is</p>
  
  <pre><code>Declare @SQL1 varchar(150), @path varchar(100), 
  
  @pathtable varchar(100), @date datetime
  
  set @date = getdate()
  
  
  -- set path for files
  
  set @path= 'C:\imp\'
  
  set @pathtable = @path + 'importfile.txt'
  
  
  
  delete from IDX
  
  --  set sql
  
  set @SQL1 = "BULK INSERT dbo.table FROM '" + @pathtable 
  
  + "' WITH (FIRSTROW = 2, MAXERRORS = 0)"
  
  
  -- Bulk insert
  
  exec(@sql1)
  </code></pre>