I have a SQL Server procedure which returns a result set, and is working well. I am adding error handling (TRY/CATCH), and in the event of an error, want to RETURN -1 to indicate an issue (Or another negative integer to maybe know the reason for the failure).
Is there a way to get the return value (As well as the result set, if required) from the procedure call?
I call the procedure like this:
Context.project_scheduled_event_payments(st.id);
In this case, I don't get a result set, as I don't need one. But I would like to know if the proc returned with NULL (All went fine), or a negative number indicating an issue:
IF(@EndDate IS NOT NULL)
BEGIN
BEGIN TRY
UPDATE scheduled_event_transaction
SET Deleted = GETUTCDATE(),
lastupdateuser = 0,
lastupdatedate = GETUTCDATE()
WHERE Scheduled_Event_ID = @scheduled_event_id
AND scheduled_payment_date > @EndDate
END TRY
BEGIN CATCH
ROLLBACK
RETURN -1
END CATCH
END
RETURN -- Success