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 2000 Forums
 Transact-SQL (2000)
 HELP WITH ROLLBACK

Author  Topic 

gtaro
Starting Member

1 Post

Posted - 2006-09-29 : 16:53:02
Hey guys. I had to write this script to clean up some bad data but I am trying to put some rollback code but for my life I dont remember how.. Its been a while.. Please help.. I've included a good chunk of the script. There is a stored procedure that runs at the end of the script that updates a history table. There are about 25 Update and Set commands like you see below. I just included one for understanding. PLEASE HELP

--Clean up null dates and F.C.ID.
Declare @guid uniqueidentifier
Set @guid = '5DD72C81-18AD-4540-868E-CD84D1FAD229'

begin transaction

UPDATE dbo.PaymentDtl
SET FacilityOrganizationId = '389', EffectiveDt = '1/5/2006 12:00:00 AM',UpdatedByPersonnelId = '2290', updateddt = getdate(), lastupdatedguid = @guid
WHERE PaymentDtlId = '4003314')

EXEC dbo.up_PaymentDtlHistoryAddByLastUpdatedGuid @guid, 6, ‘Fix UI Error’

rollback work


Kristen
Test

22859 Posts

Posted - 2006-09-29 : 19:16:43
The syntax is

BEGIN TRANSACTION

... do stuff ...

then either:

ROLLBACK

or

COMMIT

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-30 : 02:01:18
Also refer

http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -