[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

running a complex sql with begin tran commit tran

Posted on 2011-09-15
3
Medium Priority
?
505 Views
Last Modified: 2012-05-12
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,


0
Comment
Question by:patd1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Expert Comment

by:jogos
ID: 36543168
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
0
 

Author Comment

by:patd1
ID: 36543219
Thanks jogos. How about cursors? can cursors be used with begin/commit tran.
0
 
LVL 25

Accepted Solution

by:
jogos earned 2000 total points
ID: 36543424
within  a transaction mus just be vallid sql

but off-topic  try to avoid using a cursor and especialy when nested, it's slow and gets slower the more records gets into your tables
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question