We help IT Professionals succeed at work.
Get Started

Microsoft 2005 T-SQL Help

229 Views
Last Modified: 2012-05-11
Hi,

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:

   AA1


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

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

   AA3

Thanks,

Ward.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE