I have been trying to find sample code with using SQL Server 2005, I need to start an Agent Job and wait until it finishes process and then get the success or failure.

I know that I can use

EXEC MSDB.dbo.sp_start_job @Job_Name = 'JobName' 

to start the job but I can't find any sample code to poll the msdb.dbo.sp_help_job to know when it is completed and then find out if it was successful or failed.

Edit
Report