But I'm being somewhat pedantic.
The function is named as returning the job status but is in fact only returning the last executed job step ID.
How is that job step ID used to return the job status?
When any job runs, using this these functions together will return 1, meaning it's currently executing. When you pass the job name into the fx_FetchSQLAgentJobID function you get the GUID. Passing that GUID into the fx_FetchJobStatus function will return the most recent status that's been logged to the msdb.dbo.sysjobactivity table
SELECT TOP 1 ISNULL(last_executed_step_id, 0)
WHERE job_id = @JobID
ORDER BY run_requested_date DESC
The most practical uses for these functions are obviously for 0,1 - ex:
IF ((SELECT F1Settings.dbo.fx_FetchJobStatus(F1Settings.dbo.fx_FetchSQLAgentJobID(@job_1))) = 1)
EXEC msdb.dbo.sp_start_job @job_10
0 - Not executing
1 - Current executing
2 - Waiting for thread
3 - Between retries
4 - Failure during last run
5 - Suspended
6 - (not used)
7 - Performing completion actions
NULL - Job does not exists
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience