Solved

SQL 2005 Bulk Insert

Posted on 2015-01-02
1
218 Views
Last Modified: 2015-01-14
hi

I am using the following Bulk command to insert data from a .CSV file into a SQL table - this is shipment details coming from a customer.

Bulk Insert   SampleSQL
from 'C:\Sampleinput..csv'
with
(
      Fieldterminator = ',' ,
      FIRSTROW = 2,
      rowterminator = '\n'
)

This is working fine when I have data in the Sampleinput.csv file - however if no data is to be sent the user sends in a file and the second row says 'No product Shipped'

I then get this error when I bulk insert

Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

is it possible to put a clause into the Bulk insert that I can put into it that if the second row contains 'No product Shipped'  then I can skip the Bulk insert in my program ?

thanks
Mike
0
Comment
Question by:MECR123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40528037
the only option I have seen so far is this:
load the file into another table, with 1 field, and only the 2nd row (using first row and last row indicators)
then, check the contents of that table, and if it does contain the "no product shipped", you don't run the real bulk insert
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question