Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Bulk insert error output.

Author  Topic 

watersa8
Starting Member

2 Posts

Posted - 2013-08-07 : 15:15:16
HI

First of all thanks in advance for taking the time to read this.

I'm not sure if what i want to do is possible and if not no biggie but...

I'm importing a load of data out of text files and was wondering if there's any way to get more useful output from the import.
I'm doing something like

BULK INSERT Table1
FROM 'C:\FileToImport'
WITH (FIELDTERMINATOR = '|',
ERRORFILE = 'C:\ErrorLog')

This is causeing some of the records to throw truncation errors.

This is fine as its expected. What i was wondering is there any way to output the rows which are causing errors into a seperate file or table on load?

Failing this i'll just import the lot to a unrestricted table and run some queries to process it from there.

Its more curiosity and a urge to learn something/save time in the future than a i cant get by without it question.

Thanks in advance

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-08-07 : 15:31:23
That errorfile is the only error handling feature that is even close to what you are asking for. In that sense, BULK INSERT is rather limited. SSIS, of course, can do a lot more - pipe error rows to one destination and good rows to another destination and whatever else you desire. But I like the simplicity of BULK INSERT, and so like you, what I do is to import into an unrestricted table, and then process that data using T-SQL.
Go to Top of Page
   

- Advertisement -