| Author |
Topic  |
|
|
pinglu
Starting Member
2 Posts |
Posted - 05/27/2012 : 14:46:01
|
Hi,
Can anyone help me understand the following SQL,
SELECT ID,OrchestrationName,LastRunDB,RunStatus,TRIGGERFLAG,ManualExtractEndDate from dbo.IH_CILASTRUN where ProjectName = 'DynamicsSync' and OrchestrationName != 'DynamicsSync' and SkipRun != 1 AND 0 = (SELECT COUNT(*) from dbo.IH_CILASTRUN where ProjectName = 'DynamicsSync' and RunStatus = 'INPROCESS')
The thing that I don't understand is the "AND 0 = (SELECT COUNT(*) from dbo.IH_CILASTRUN where ProjectName = 'DynamicsSync' and RunStatus = 'INPROCESS')", I assume this is not a correlated query, but if it is not, then how do I interpret the result? Thanks in advance.
|
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47069 Posts |
Posted - 05/27/2012 : 15:04:56
|
the way its written its not correlated to main query. what it does is it will cause query to return a resultset only if there are no rows satisfying conditions ProjectName = 'DynamicsSync' and RunStatus = 'INPROCESS' in the table dbo.IH_CILASTRUN
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
pinglu
Starting Member
2 Posts |
Posted - 05/27/2012 : 15:24:04
|
Thanks for the reply, now I understand.
quote: Originally posted by visakh16
the way its written its not correlated to main query. what it does is it will cause query to return a resultset only if there are no rows satisfying conditions ProjectName = 'DynamicsSync' and RunStatus = 'INPROCESS' in the table dbo.IH_CILASTRUN
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47069 Posts |
Posted - 05/27/2012 : 15:45:38
|
no problem...you're welcome 
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
SwePeso
Patron Saint of Lost Yaks
Sweden
29138 Posts |
Posted - 05/27/2012 : 18:29:14
|
SELECT ID,OrchestrationName,LastRunDB,RunStatus,TRIGGERFLAG,ManualExtractEndDate from dbo.IH_CILASTRUN where ProjectName = 'DynamicsSync' and OrchestrationName != 'DynamicsSync' and SkipRun != 1 AND NOT EXISTS (SELECT * from dbo.IH_CILASTRUN where ProjectName = 'DynamicsSync' and RunStatus = 'INPROCESS')
N 56°04'39.26" E 12°55'05.63" |
 |
|
| |
Topic  |
|