DECLARE @job NVARCHAR(MAX)='DR00510 - TriaFin subscription agent';

IF NOT EXISTS(
     SELECT [j].[name] AS [job_name],
            [j].[job_id],
            [a].[run_requested_date],
            [a].[next_scheduled_run_date],
            [a].[start_execution_date],
            [a].[stop_execution_date]
     FROM [msdb].[dbo].[sysjobs] [j]
         JOIN (
              SELECT MAX([session_id]) AS [session_id],
                     [job_id]
              FROM [msdb].[dbo].[sysjobactivity] [ia]
              GROUP BY [job_id]
              ) [sess] ON [sess].[job_id] = [j].[job_id]
         JOIN [msdb].[dbo].[sysjobactivity] [a] ON [a].[job_id] = [j].[job_id] AND [sess].[session_id] = [a].[session_id]

     WHERE [j].[name] = @job
       AND [start_execution_date] IS NOT NULL
       AND [stop_execution_date] IS NULL
     )
	AND EXISTS(SELECT 1 FROM msdb.dbo.[sysjobs] WHERE name=@job)
BEGIN
    EXEC [msdb].[dbo].[sp_start_job] @job_name = @job
    PRINT 'started job '+@job
END