troubleshooting Question

Microsoft 2005 T-SQL Help

Avatar of whorsfall
whorsfallFlag for Australia asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008
8 Comments1 Solution232 ViewsLast Modified:

I am after a T-SQL (Microsoft SQL 2005) that can do the following.

Ok Table1 Contains

SiteCode    Package ID  Targeted    Installed
---------   ----------  --------    ---------
AA1         P1          1           0
AA1         P2          1           1
AA1         P3          1           0
AA1         P4          1           1

AA2         P1          1           1
AA2         P2          0           0
AA2         P3          1           1

AA3         P1          1           1
AA3         P3          1           1
AA4         P4          1           1

Ok I would like to work out how to do SQL that does the following:

1. Return the sitecode where there any of the result set is Targetd = 1 and Installed = 0.
   So the result set I would back is a single row being:


2. Return the sitecode where only if every record that every Row that is Targeted = 1
   also has Installed = 1. (So if there is anything that is Targeted = 1 and Installed = 0
   it would be eliminated). So the result I would get back here would be

3. Return the sitecode where only where every row must match Targeted = 1 and Installed = 1
   So the result returned would be:




Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros