0

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..

4
  • 1
    How are you testing for the return value of the stored procedure?
    – Ann L.
    Feb 8, 2014 at 15:25
  • Also, how do you know that the return value is equal to the number of queries executed in the procedure, as you claim?
    – Ann L.
    Feb 8, 2014 at 15:31
  • @AnnL.: Perhaps the OP was referring to the "... row(s) affected" messages when speaking about "count of no of queries executed".
    – Andriy M
    Feb 8, 2014 at 15:36
  • @AndriyM True; I just noticed the OP has turned NOCOUNT off, rather than on, so he or she would indeed get "... row(s) affected" messages.
    – Ann L.
    Feb 8, 2014 at 15:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.