I have a stored procedure which is the first step in an SQL Job. The SP compares dates in 2 tables, if they equal then the SQL job can continue, but if they are not I need to return value from the SP that causes the SQL Job to trigger it's on failure action.
What is the best way to do this? Is it with an RAISERROR statement or just return a value like -99?
Seems such an obvious question, but I've never thought about it before until now.
Whichever way you want. You can use a try/catch and raiserror. That can allow you to write the error to the event log as well if desired.
Typically, I'd just use an IF statement that does a return and then proceed with the rest of the code otherwise.
I think it's a matter of preference/requirements, though. Either will get the job done.