Link to home
Start Free TrialLog in
Avatar of patd1
patd1Flag for United States of America

asked on

running a complex sql with begin tran commit tran

I have a complex sql that has several steps to eventually update some records in a table. To identify the records it pulls some records in three temp tables (#Priority, #pi, #he) and then finds distinct common rows by joining those three temp tables into a fourth temp table #cross, then fires an update  and a delete command which looks like the code copied below, and then it uses cursors to update some columns in another table.

UPDATE OMC
		SET SCID = c.PChart,
			SCProductID = 9,
			SCHREID = c.HREID,
			ETypeID = 2,
			ChangeID = System_User,
			ChangeDate = getdate()	
		FROM dbo.OMChart OMC
		JOIN #cross c
		ON   OMC.MCID = c.HDC
		WHERE SCID is null


DELETE FROM OMChart
		WHERE MCID IN (SELECT mc.MCID
									FROM dbo.OMChart mc
									JOIN #cross c
									  ON mc.MCID = c.PChart
									WHERE  mc.SCID IS NULL)

Open in new window



My question is that will this sql that involves all these temp tables in memory and cursors run with begin tran and commit tran. I want to see how many rows are inserted in the temp tables and how many rows are updated in each step before i commit the tran.

Thanks,


Avatar of jogos
jogos
Flag of Belgium image

temp tables can be used within begin/commit tran

How much records are affected in your last statement you can by using the @@ROWCOUNT directly after that statement. cfr http://msdn.microsoft.com/en-us/library/ms187316(v=SQL.110).aspx
Avatar of patd1

ASKER

Thanks jogos. How about cursors? can cursors be used with begin/commit tran.
ASKER CERTIFIED SOLUTION
Avatar of jogos
jogos
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial