It says:If the query:SELECT tempdb.dbo.DEX_LOCK.table_path_nameFROM DYNAMICS.dbo.ACTIVITY INNER JOINtempdb.dbo.DEX_LOCK ON DYNAMICS.dbo.ACTIVITY.SQLSESID = tempdb.dbo.DEX_LOCK.session_idWHERE (tempdb.dbo.DEX_LOCK.table_path_name LIKE '%SVC%')) AS subquqer
returns any rows, run the stored procedure sp_stop_job with the @job_name parameter set to 'Returns Processing'FWIW I would rearrange it a bit and reformat it for readability like this:IF 0 < -- If any rows received from this subquery ( SELECT COUNT(*) FROM( SELECT tempdb.dbo.DEX_LOCK.table_path_name FROM DYNAMICS.dbo.ACTIVITY INNER JOIN tempdb.dbo.DEX_LOCK ON DYNAMICS.dbo.ACTIVITY.SQLSESID = tempdb.dbo.DEX_LOCK.session_id WHERE tempdb.dbo.DEX_LOCK.table_path_name LIKE '%SVC%') AS subquqery ) BEGIN -- Run this stored procdure EXEC sp_stop_job @job_name = 'Returns Processing'; END;
Though I would replace my generic comments with the actual business rules for your application