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)
 Record by record processing

Author  Topic 

tanzeel_mirza
Starting Member

1 Post

Posted - 2013-11-01 : 10:54:12
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-11-01 : 11:20:38
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
   

- Advertisement -