ALTER PROCEDURE [dbo].[usp_PracticeBillingAddress_Update]
(
@PracticeID
INT, @AddressID INT, @AttentionOf VARCHAR(50) , @AddressLine1 VARCHAR(50), @AddressLine2 VARCHAR(50), @City VARCHAR(50), @State CHAR(2), @ZipCode CHAR(5), @ZipCodePlus4 CHAR(4), @ModifiedUserID INT)
AS
BEGIN
DECLARE @TransactionCountOnEntry INT -- Transaction Count before the transaction begins, @Err INT -- holds the @@Error code returned by SQL ServerSELECT @Err = @@ERRORSET TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDIF @Err = 0BEGIN SELECT @TransactionCountOnEntry = @@TRANCOUNTBEGIN TRANSACTIONEND IF @Err = 0BEGIN UPDATE dbo.AddressSETAddressLine1
= @AddressLine1, AddressLine2 = @AddressLine2, City = @City, State = @State, ZipCode = @ZipCode, ZipCodePlus4 = @ZipCodePlus4, ModifiedUserID = @ModifiedUserID, ModifiedDate = GETDATE()WHEREAddressID
= @AddressIDSET @Err = @@ERRORENDIF @Err = 0BEGINUPDATE dbo.PracticeBillingAddressSETAttentionOf
= @AttentionOf, ModifiedUserID = @ModifiedUserID, ModifiedDate = GETDATE()WHEREPracticeID
= @PracticeID AND AddressID = @AddressIDSET @Err = @@ERRORENDExec usp_PracticeBillingAddress_UpdateCentralDecentral @practiceID, @ModifiedUserIDIF @@TranCount > @TransactionCountOnEntryBEGINIF @Err = 0COMMIT TRANSACTIONELSEROLLBACK TRANSACTION-- Add any database logging here ENDRETURN @ErrEND
Monday, June 7, 2010
Update 2 tables in a transaction
Yuiko was writing a query the other day to update 2 tables at the same time.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment