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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Record by record processing
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tanzeel_mirza
Starting Member

India
1 Posts

Posted - 11/01/2013 :  10:54:12  Show Profile  Reply with Quote
Hi All

I am trying to create a program in TSQL which reads the data from a source table and loads into a target table.
I want to process the records one by one and load the records in the target in a group of 250 records. The Group is identified by an ID column which is an Integer value and keeps incrementing after every 250 records.
While processing one by one record if for any record gets errored out, I have to capture that in a separate log table and move to the next record for processing.
I am using Cursor to do that.

Can anyone suggest me how can I achieve it?

Thanks
Tanzeel

James K
Flowing Fount of Yak Knowledge

3760 Posts

Posted - 11/01/2013 :  11:20:38  Show Profile  Reply with Quote
Usually processing data one record at a time is not a good way to program SQL Server. Instead, consider using set-based query to:

1. Test for all the rows that would cause an error message. Log such records, and generate any error messages required.
2. Insert the records that do pass the test into your target table.

If you can post the DDL for the tables and sample data, many folks on the forum would be able to offer more concrete suggestions and even code to do it. If you need help posting, take a look at this article: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
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.03 seconds. Powered By: Snitz Forums 2000