Bulk Insert with Errorfile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ma Oo
    New Member
    • Nov 2011
    • 1

    #1

    Bulk Insert with Errorfile

    I want error log file when I do bulk insert. My sample code is :
    Code:
    INSERT INTO tbl_test(
    	USER_ID, CODE, EXCHANGE, UPDATED_DATE)
    SELECT LTRIM(RTRIM(USER_ID)),		
    		LTRIM(RTRIM(CODE)), 		
    		EXCHANGE = '11',
    		UPDATED_DATE = getdate()
    	    FROM OPENROWSET(
    		BULK N'c:\test.txt',
    		FORMATFILE='c:\test.fmt.txt', 
    		ERRORFILE = 'c:\ERROR.txt') A
    But the error log is not appeared in this way. What's wrong with this code? 
    When I tried like below, it's work well.
    BULK INSERT tbl_test
    
    FROM 'c:\test.txt'
    WITH
    (
    FIELDTERMINATOR='|',
    ROWTERMINATOR = '\n',
    FORMATFILE='c:\test.fmt.txt', 
    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.
    Last edited by NeoPa; Nov 25 '11, 08:12 PM. Reason: Added mandatory [CODE] tags for you
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What you have will put the error log on the C drive of the SQL Server.

    Comment

    Working...