I have the following SP. I am not getting proper return value from SP. I need to know if all queries placed inside SP are executed successfully or not.
BEGIN TRAN
SET NOCOUNT off;
if @Operation ='A'
begin
INSERT INTO table1 (---) values (--)
INSERT into table2(--)values(--)
IF (@@ERROR <> 0) GOTO ERR_HANDLERUpdate
end
else if @Operation ='B'
begin
--- another update query----
IF EXISTS(Select * from Med Where a=@a)
Begin
Delete from Med where a=@a
end
INSERT into Med(--)values(--)
IF (@@ERROR <> 0) GOTO ERR_HANDLERUpdate
end
COMMIT TRAN
RETURN 1
ERR_HANDLERUpdate:
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
RETURN 0
I want to return 0 if any error occurs and 1 if all queries executes successfully without any error. But the procedure is returning count of no of queries executed in procedure. How to check if procedure is executes successfully and return value..Help Me..