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 2005 Forums
 Transact-SQL (2005)
 related to cursor

Author  Topic 

shankbond
Starting Member

5 Posts

Posted - 2009-08-04 : 09:03:00
Hi,
I am using cursor to access the rows of table1 then manipulate the table row by row; depending upon some conditions I have to insert some of the field values into some other table table2.

how should I do that?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-04 : 09:06:06
By not using a CURSOR at all.

You can use the new OUTPUT operator to do this.
See http://weblogs.sqlteam.com/peterl/archive/2007/10/03/New-OUTPUT-operator.aspx
OUTPUT makes you insert all records that are updated.

However if you need to "manipulate" or UPDATE some records and then log or insert only a subset of the updated records, you can use composable DML described in this post
http://weblogs.sqlteam.com/peterl/archive/2009/04/08/Composable-DML.aspx
The composable DML is a SQL Server 2008 feature.
You can make a workaround using the OUTPUT to a temp table and from the temp table insert a subset to another table.


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-08-04 : 09:48:30
good post on composable DML Peter
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-04 : 09:57:32
Thank you.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -