SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query about using 0 = (select Count(*) in where
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pinglu
Starting Member

2 Posts

Posted - 05/27/2012 :  14:46:01  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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/

Go to Top of Page

pinglu
Starting Member

2 Posts

Posted - 05/27/2012 :  15:24:04  Show Profile  Reply with Quote
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/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 05/27/2012 :  15:45:38  Show Profile  Reply with Quote
no problem...you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29138 Posts

Posted - 05/27/2012 :  18:29:14  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000