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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Record by record processing
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

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?


James K
Flowing Fount of Yak Knowledge

3873 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:
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000