473,795 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BULK INSERT not loading all rows from a text file.

1 New Member
I have written a stored procedure that is used to load data into a SQL Server 2000 and 2005 databases from some 40ish different text files. One of the text files is loading all of the rows apart from the last one. No error message is issued when this happens.
The command I am using to load the data is as follows:

Expand|Select|Wrap|Line Numbers
  1. BULK INSERT BasicDataT FROM 'E:\Temp\Food GNRLv3\BasicData.txt' WITH ( FORMATFILE = 'C:\Taxcalc\Client\InitialInstall\BasicData.fmt', MAXERRORS=0, BATCHSIZE=500000,CHECK_CONSTRAINTS, ERRORFILE='C:\Taxcalc\Basicdata.bad') 
(I understand that the ERRORFILE option only works in SQL Server 2005, but 2000 seems to be able to ignore it without a problem.)
To fix the problem, I have to insert a 'tab' after the last section of data in the last row.

Expand|Select|Wrap|Line Numbers
  1. 49708    60646    2006-11-15    1    CITY SALES TAX    1    00    00    02    02    
  2. 49709    60647    1990-01-01    1    GROSS RECEIPTS TAX    2    03    01    02    02<tab>
Unless the last tab is manually inserted, the last row does not get loaded to the database, and no error message is issued. If the tab is inserted all of the data is loaded correctly. However, the text files come from a third party so I cannot ensure that this problem will not occur again.

The .fmt file used to load the data is as follows:

Expand|Select|Wrap|Line Numbers
  1. 8.0
  2. 11
  3. 1       SQLCHAR       0       12      "\t"                      1     BasicDataID            ""
  4. 2       SQLCHAR       0       12      "\t"                      2     BasicTaxOverrideID     ""
  5. 3       SQLCHAR       0       24      "\t"                      3     LegalEffectiveDate     ""
  6. 4        SQLCHAR       0       12      "\t"                      4     ReleaseNo              ""
  7. 5       SQLCHAR       0       50      "\t"                      5     BasicDataDesc          SQL_Latin1_General_CP1_CI_AS
  8. 6       SQLCHAR       0       1       "\t"                      6     PassFlag               SQL_Latin1_General_CP1_CI_AS
  9. 7       SQLCHAR       0       2       "\t"                      7     PassType               SQL_Latin1_General_CP1_CI_AS
  10. 8       SQLCHAR       0       2       "\t"                      8     BaseType               SQL_Latin1_General_CP1_CI_AS
  11. 9       SQLCHAR       0       2       "\t"                      9     DateFlag               SQL_Latin1_General_CP1_CI_AS
  12. 10      SQLCHAR       0       2       "\t"                      10    RoundingLevel          SQL_Latin1_General_CP1_CI_AS
  13. 11      SQLCHAR       0       8       "\r\n"                    11    TaxGroupingCode        SQL_Latin1_General_CP1_CI_AS
  14.  
My question is, is there any way to trigger an error message to denote that (in my example) the last row did not get loaded successfully? Is there a parameter associated with the BULK INSERT command that I am not currently using that could help with this problem?
Jun 22 '07 #1
0 2615

Sign in to post your reply or Sign up for a free account.

Similar topics

0
5375
by: cmars | last post by:
Hi, I want to insert massive amounts of data in near real-time into a MySQL database. The data is in a structured binary format, and I have code that parses the data into logical data structures. Right now I can load into a MySQL database via ODBC, but I need to improve throughput. How can I bulk insert the data more efficiently? I would prefer not to use LOAD FILE because it involves converting the binary format to text, which will...
2
8668
by: David Sharp | last post by:
I've been doing some experiments with speeding up copying tables of approximately 1 million rows between databases using BCP and BULK INSERT. I noticed that the total time for removing the indexes (non-clustered) and then recreating them after the BULK INSERT was significantly less than just doing the BULK INSERT with the indexes left there, even though I specified TABLOCK. I would have expected SQL Server not to update the index until...
5
4901
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or big) problem with my code that someone can point out that may save me some time. TIA CBL
7
12131
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the servers using sp_addlinkedserver on both database servers. When I call the Commit API of oledb I get the following error: Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:
6
12358
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of 10 columns into a table with 12. How can I specify which columns to insert to? I think format files are what I'm supposed to use, but I can't figure them out. I've also tried using a view, as was suggested on one of the many websites I've...
16
17021
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
5
6853
by: yeoj13 | last post by:
Hello, I have a db2load script I'm using to populate a large table. Ideally, my target table is required to have "Not Null" constraints on a number of different columns. I've noticed a huge performance hit when I load the target table with "Not Null" constraints as compared to loading a target table without the constraints.
0
2093
by: rshivaraman | last post by:
BULK INSERT bill_tbl FROM 'd:\ftp_Data\in\baddress.dat' WITH ( FIELDTERMINATOR = ';', ROWTERMINATOR = '\n' ) --------------------------------- This is the query used to populate bill_tbl. Actually this baddress.dat contain rowdelimiter of \r\n.
2
5895
by: zswanson | last post by:
Hi everyone, I receive a variety of text based files that seperates each row by a single delimiter, usually '~'. I use BULK INSERT to transfer the file from a text file to a temporary table. It works fine for most of the files (which use '~' as the delimiter for the rows), but for some reason I can't get it to work for a particular file. The file looks like it uses a new line character as the row delimiter, so I put in '\n' as the row...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.