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
 General SQL Server Forums
 New to SQL Server Programming
 Bulk Insert debugging

Author  Topic 

indupriyav
Starting Member

13 Posts

Posted - 2013-06-20 : 06:14:20
Hi,

A SQL procedure is doing a bulk insert from a file to a table and it fails.

Usually it fails due to date format issues. I checked the file and the date formats were fine. Im not able to figure out any other format issue in the file.

While doing bulk insert, is there any way to trap which row identified by primary key is erroring out.

This is possible in oracle. Is there a way in SQL Server.

Thanks!!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-20 : 06:20:34
You can find errored rows if you use ssis by adding OnError action to redirect row.
Otherwise you might have to do it it two steps
first get file data onto staging table, then do required validations to find offending rows and insert the correct ones.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

indupriyav
Starting Member

13 Posts

Posted - 2013-06-20 : 07:14:30
Thanks.

BTW I dont want to do major changes. if there is data issue the whole file should not upload like the current process.

just want to know which row errored out.

Is there any good link for ssis and Onerror which you have mentioned.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-20 : 07:22:09
quote:
Originally posted by indupriyav

Thanks.

BTW I dont want to do major changes. if there is data issue the whole file should not upload like the current process.

just want to know which row errored out.

Is there any good link for ssis and Onerror which you have mentioned.


Still if you want row wise tracking of errors you obviously need a row by row parsing mechanism. That can only be possible using SSIS file source or using staging table approach

Alternatively you could use a language like .NET to create a file system object and load and parse the file but again that can cause performance issues especially for large files.
My preferred method is using Staging table approach if in T-sql or using SSIS otherwise.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -