SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Bulk Insert debugging
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

indupriyav
Starting Member

India
13 Posts

Posted - 06/20/2013 :  06:14:20  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 06/20/2013 :  06:20:34  Show Profile  Reply with Quote
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

India
13 Posts

Posted - 06/20/2013 :  07:14:30  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 06/20/2013 :  07:22:09  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000