Solved

SQL 2005 Bulk Insert

Posted on 2015-01-02
1
209 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
Comment Utility
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

13 Experts available now in Live!

Get 1:1 Help Now