Solved

SQL 2005 Bulk Insert

Posted on 2015-01-02
1
211 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
1 Comment
 
LVL 142

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Order by but want it in specific order 2 26
configure service broker on all databases 2 77
How to query LOCK_ESCALATION 4 40
INSERT DATE FROM STRING COLUMN 18 50
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will useā€¦
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now