Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send a return value from an sp to a job?

Status
Not open for further replies.

takaoki

Programmer
Aug 28, 2008
39
ZA
Hello,

Is there a way to send a return value from a stored procedure (which is called from a job step) back to the job?

Basically, I want to be able to send a "failure" code back to the job from the stored procedure that will fail the job step.

Is this possible?

Thanks
 
SP can returns only integers.
If you want to return something else you should use otuput parameters. But you could use integers to return "Success" or "Faulre"



Code:
CREATE PROCEDURE MyTestSP
 @SomeParameter int
AS
  BEGIN
     DECLARE @RetVal int
     IF @SomeParameter < 1
        BEGIN
           --- The SP returns SUCCESS
           SET @RetVal = 1
        END
     ELSE
        BEGIN
           --- The SP returns Error
           SET @RetVal = -1
        END
    RETURN @RetVal
  END
GO


DECLARE @Result int
EXEC @REsult = MyTestSP -10
IF @REsult = 1
   print 'Success'
ELSE
   print 'Error'

EXEC @REsult = MyTestSP 10
IF @REsult = 1
   print 'Success'
ELSE
   print 'Error'






Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thanks... but how will the calling job recognize that a failure code has been sent? I need to communicate with the job step... if possible.
 
What job is that?

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Really!?! :)
(sorry, I can't resist)


Created how?
With SSIS maybe.



Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top