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.
Author |
Topic |
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2012-11-30 : 13:18:01
|
I was given this script by a co-worker but when I run it it only does one update then stops, when I close out of management studeio I am told there are uncommented transactions. If I comment out the SELECT code everything works fine. I have been looking it over for about 20 minutes not I do not see anything wrong. Can anyone point out what I am missing?BEGIN TRY BEGIN TRANSACTION USE DOD; --------------------------------------------------------------------------- --They can't reconcile the order because the IsReconciled flag is Y. --------------------------------------------------------------------------- DECLARE @MnfstID Int; SELECT @MnfstID = m.MnfstID FROM dbo.Manifest AS m WITH (NOLOCK) WHERE m.mnfstid = ( SELECT mnfstid FROM OrderManifest AS om WITH (NOLOCK) WHERE om.Ordrnmbr = 503326 ); SELECT @MnfstID; RETURN; --------------------------------------------------------------------------- --Once you have the mnfstid value you can update the IsReconciled flag to N --------------------------------------------------------------------------- UPDATE m SET m.IsReconciled = 'N' --Select m.* FROM dbo.Manifest AS m WHERE m.MnfstID = @MnfstID; --COMMIT ROLLBACKEND TRYBEGIN CATCH ROLLBACKEND CATCH -- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2012-11-30 : 13:34:32
|
first make sure you still don't have any uncommitted transactions:run this: dbcc opentranIf it reports that there are then run this: ROLLBACK>> I am told there are uncommented transactions.The message is that you have uncommitted transactions. And that is because you have "return" between your begin tran and commit tran.Because you only have one statement that actually changes data you can remove the transaction completely.so take out the "RETURN" and the BEGIN/COMMIT/ROLLBACK transaction code.Be One with the OptimizerTG |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2012-11-30 : 13:49:52
|
Thanks, I removed the return and that fixed it. I thought I tried that in my debugging but I guess I meissed it.-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-11-30 : 14:00:44
|
I'd suspect it's the USE statement. You begin a transaction, then, possibly, switch databases. And as mentioned you a RETURNing witout commiting or romming back. |
|
|
|
|
|