Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help understanding what this query is doing

Author  Topic 

junior6202
Starting Member

45 Posts

Posted - 2014-12-30 : 10:23:56


if (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) <> 0
begin
exec sp_stop_job @job_name = 'Returns Processing'
end

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-30 : 10:54:29
It says:

If the query:


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 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
Go to Top of Page

junior6202
Starting Member

45 Posts

Posted - 2014-12-30 : 15:11:59
Thank you for your help.
Go to Top of Page
   

- Advertisement -