HelloI’m using the procedure below with Transactions. I want to have a backup record in case somebody updates a contact profile. I wanted to test how the transactions are working and renamed with purpose the column LastName from ContactBackup table to LastName2. Then I’m getting the following error message:Message "Invalid column name 'LastName'. Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 0, current count = 1.
I was wondering what it means. Is something wrong with my Trans syntax? Below is the procedure:ALTER PROCEDURE [dbo].[wsp_UpdateContactProfile] ( @contactCode char(30), @prefix char(20), @firstName char(50), @middleName char(50), @lastName char (50) )ASBEGIN SET NOCOUNT ON; BEGIN TRAN -- Will create a backup record of existing Contact INSERT INTO ContactBackup(ContactCode, Prefix, FirstName, MiddleName, LastName) VALUES(@contactCode, @prefix, @firstName, @middleName, @lastName) IF @@ERROR <> 0 BEGIN ROLLBACK TRAN return 10 END UPDATE Contact SET Prefix = @prefix, FirstName = @firstName, MiddleName = @middleName, LastName = @lastName where contactCode = @contactCode IF @@ERROR <> 0 BEGIN ROLLBACK TRAN return 11 END COMMIT TRANENDGO
Thanks in advance!