Ok I will try and be as clear as possible. I have two tables one is pp and one is cp. I have one entry field is called classnum in the PP table. The CP table is my customer number. For some reason the code I have now is still pulling the wrong results and I am sure I have something wrong.
The results I am trying to obtain: Show me all customers (custnum) that does not have any packages that have a class of 17.
Each package in this PP table has different classnum.
The results I am getting: It is showing the unique customer numbers but it is showing me ALL unique customer numbers. Currently it is pulling 1558 rows which is my customer count. If the query is correct it should only pull two. As I know for a fact there are two unique customers with a package class of 17.
I have attached the query that I have now.
SELECT DISTINCT TOP (100) PERCENT cp.custnum
FROM KC_Freeside.dbo.cust_pkg AS cp INNER JOIN
KC_Freeside.dbo.part_pkg AS pp ON pp.pkgpart = cp.pkgpart
WHERE (cp.cancel IS NULL) AND (pp.classnum <> 17) AND (pp.freq <> '0')
ORDER BY cp.custnum