Home Forums SQL Server 7,2000 Administration SQL 2000 - How long has a job (all steps inclusive) been running? RE: SQL 2000 - How long has a job (all steps inclusive) been running?

  • It is possible if you use xp_sqlagent_enum_jobs and then convert the Job ID value to a string value using the fn_varbintohexstr function and then find a row in sysprocesses where the program name contains that value. The login_time value in sysprocesses is then the start time of the job.

    For example,

    CREATE TABLE #jobs

    (

    Job_ID uniqueidentifier,

    Last_Run_Date int,

    Last_Run_Time int,

    Next_Run_Date int,

    Next_Run_Time int,

    Next_Run_Schedule_ID int,

    Requested_To_Run int,

    Request_Source int,

    Request_Source_ID varchar(100),

    Running int,

    Current_Step int,

    Current_Retry_Attempt int,

    State int

    )

    INSERT INTO #jobs EXECUTE master.dbo.xp_sqlagent_enum_jobs 1 ,''

    ---select * from #jobs where Running =1

    SELECT login_time, program_name FROM sysprocesses WHERE lower(program_name) LIKE

    (SELECT '%' + master.dbo.fn_varbintohexstr(#jobs.Job_ID) + '%' FROM #jobs

    WHERE Running=1)

    DROP TABLE #jobs