473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Bulk Insert with Errorfile

1
I want error log file when I do bulk insert. My sample code is :
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tbl_test(
  2.     USER_ID, CODE, EXCHANGE, UPDATED_DATE)
  3. SELECT LTRIM(RTRIM(USER_ID)),        
  4.         LTRIM(RTRIM(CODE)),         
  5.         EXCHANGE = '11',
  6.         UPDATED_DATE = getdate()
  7.         FROM OPENROWSET(
  8.         BULK N'c:\test.txt',
  9.         FORMATFILE='c:\test.fmt.txt', 
  10.         ERRORFILE = 'c:\ERROR.txt') A
  11. But the error log is not appeared in this way. What's wrong with this code? 
  12. When I tried like below, it's work well.
  13. BULK INSERT tbl_test
  14.  
  15. FROM 'c:\test.txt'
  16. WITH
  17. (
  18. FIELDTERMINATOR='|',
  19. ROWTERMINATOR = '\n',
  20. FORMATFILE='c:\test.fmt.txt', 
  21. ERRORFILE = 'c:\ERROR.txt'
But I want to add some hard_coded field other than the fields included in the file. So I need to use with openrowset. Do you have any idea with second method to add some more fields, or any advise of what is wrong with first method? Thank you.
Nov 25 '11 #1
1 4621
Rabbit
12,516 Expert Mod 8TB
What you have will put the error log on the C drive of the SQL Server.
Nov 25 '11 #2

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

Similar topics

2
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. ...
5
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...
7
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...
6
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...
16
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...
3
by: moonriver | last post by:
Right now I develop an application to retrieve over 30,000 records from a binary file and then load them into a SQL Server DB. So far I load those records one by one, but the performance is very...
0
by: NickW | last post by:
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...
0
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....
2
by: chompy | last post by:
I am trying to dynamically create the errorfile name with the date the error occured. The error occurs at ERRORFILE = @errorfilename Is this possible? Here is the script I have so far... ...
1
by: John A Grandy | last post by:
Since I want BULK INSERT to fail on unique key violations , I set MAXERRORS=0 But how to determine which row of the flat-file contains the duplicate ? Apparently, ERRORFILE is not created for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.