|
gemispence
Yak Posting Veteran
71 Posts |
Posted - 2006-03-03 : 11:50:43
|
| I want to insure that each of my insert statements in a stored proc are rolled back if any of the inserts fail. I already have the below statement with error handling but is this correct? It seems to me that all the steps should be made part of an entire transaction so if one part fails then it all fails. Can someone help me w/ the syntax of this??CREATE PROCEDURE Addrecords AS--USERSINSERT INTO [Production].[dbo].[USERS]([LastName], [UserName], [EmailAddress], [Address1], [WorkPhone], [Company], [CompanyWebsite], [pword], [IsAdmin], [IsRestricted],[AdvertiserAccountID])SELECT dbo.fn_ReplaceTags (convert (varchar (8000),Advertisername)), [AdvertiserEmail], [AdvertiserEmail],[AdvertiserAddress], [AdvertiserPhone], [AdvertiserCompany], [AdvertiserURL], [AccountNumber],'3',0, [AccountNumber]FROM productionWHERE not exists (select * from users Where users.Username = temp.AdvertiserEmail)AND validAD=1IF @@ERROR <> 0BEGIN ROLLBACK TRAN RETURNEND--PROPERTYINSERT INTO [Production].[dbo].[Property]([ListDate],[CommunityName],[TowerName],[PhaseName],[Unit], [Address1], [City], [State], [Zip],[IsActive],[AdPrintId])SELECT [FirstInsertDate],[PropertyBuilding],[PropertyStreetAddress],PropertyCity + ' ' + PropertyState + ' ' + PropertyZipCode as PhaseName,[PropertyUnitNumber],[PropertyStreetAddress],[PropertyCity], [PropertyState], [PropertyZipCode],'0',[AdPrintId]FROM [Production].[dbo].[Temp]WHERE AdvertiserEmail IS NOT NULLAND validAD=1 IF @@ERROR <> 0BEGIN ROLLBACK TRAN RETURNEND |
|