This code will get the value when run in a job.
DECLARE @MaxID INT;
SELECT @MaxID = MAX(instance_id)
FROM [msdb].[dbo].[sysjobhistory]
WHERE job_id = CONVERT(uniqueidentifier, $(ESCAPE_NONE(JOBID)))
AND step_id = 1;
The SQL Guy @ blogspot[/url]
@SeanPearceSQL
About Me[/url]