Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL 2005 Bulk Insert

Posted on 2015-01-02
1
Medium Priority
?
242 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 1500 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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