SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need help debuging SQL script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Eagle_f90
Constraint Violating Yak Guru

USA
422 Posts

Posted - 11/30/2012 :  13:18:01  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
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
	ROLLBACK
END TRY

BEGIN CATCH
	ROLLBACK
END CATCH


--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

TG
Flowing Fount of Yak Knowledge

USA
6059 Posts

Posted - 11/30/2012 :  13:34:32  Show Profile  Reply with Quote
first make sure you still don't have any uncommitted transactions:
run this: dbcc opentran
If 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 Optimizer
TG
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

USA
422 Posts

Posted - 11/30/2012 :  13:49:52  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
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
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4610 Posts

Posted - 11/30/2012 :  14:00:44  Show Profile  Reply with Quote
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.

Edited by - Lamprey on 11/30/2012 14:25:56
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000