Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Using Return to exit stored procedure, but SQL Agent marks as successful. How to make it an error?

$
0
0

SQL Server 2008R2.

I have a stored procedure which uses an IF/ELSE statement. This runs inside a SQL Agent job
In the IF section, I check for the value of a parameter.
If the value is NULL, I want to exit the stored procedure, and relay to SQL Agent this step failed.
I'm currently using the following.  This will exit, but SQL Agent reports success:

IF @LASTDAY is NULL
	BEGIN 
	Print ''No records were loaded into TABLE X - Sending Email''		
	RETURN
	END

Any thoughts on how to tell SQL Agent the step failed? 

-Al H


Viewing all articles
Browse latest Browse all 23857

Trending Articles