SQL Server does not have a built-in function for checking the status of a stored procedure, but you can write something that will do something similar. In our case, we created a registration function that sends a message after each process in a stored process.
Let's say you have a saved proc that runs several requests:
SELECT * FROM yourTable UPDATE ... SET ... DELETE FROM ...
After each request / process, you can enter a step that will send data to the logging table:
SELECT * FROM yourTable -- log query INSERT INTO LogTable (DateComplete, Status, TaskId) VALUES (getdate(), 'Complete', 1) UPDATE ... SET ... -- log query INSERT INTO LogTable (DateComplete, Status, TaskId) VALUES (getdate(), 'Complete', 2) DELETE FROM ... -- log query INSERT INTO LogTable (DateComplete, Status, TaskId) VALUES (getdate(), 'Complete', 3)
You can do this even more by using the TRY...CATCH block around your queries, in which you may have different messages about whether the process was successful or failed.
Taryn source share