Good, so I hope that I can explain this question well enough, because I feel that it will be difficult.
I have two tables that I work with today. They look like this:
@pset table (PersonID int, SystemID int, EntitlementID int, TargetID int) @Connector table (TargetName varchar(10), fConnector bit)
The first table contains records that tell me, oh, this person has this system, which consists of these rights, which have these goals. A bit complicated, but stay with me. The second stores the name TargetName, and then whether this target has a connector in my non-theoretical system.
What I'm trying to do is combine these two tables so that I can see the target flag for each row in @pset. This will help me later, as you will see.
If every right in the system has a connector to the target (the flag is true for all of them), then I would like to know.
Everyone else should go to another table.
This is what I tried to do, but it did not work. I need to know where I was wrong. Hopefully someone with more experience than me can answer.
-- If the count(123) = 10 (ten rows with SystemID = 123) and the sum = 10, cool. select pset.*, conn.fConnector from @pset pset inner join vuTargets vt on vt.TargetID = pset.TargetID inner join @conn conn on conn.TargetName = vt.TargetName group by ProfileID, SystemRoleID, EntitlementID, TargetID, fConnector having count(SystemID) = sum(cast(fConnector as int)) order by ProfileID
and
-- If the count(123) = 10 (ten rows with SystemID = 123) and the sum <> 10 select pset.*, conn.fConnector from @pset pset inner join vuTargets vt on vt.TargetID = pset.TargetID inner join @conn conn on conn.TargetName = vt.TargetName group by ProfileID, SystemRoleID, EntitlementID, TargetID, fConnector having count(SystemID) <> sum(cast(fConnector as int)) order by ProfileID
Unfortunately, they do not work :(
Edit
Here is a screenshot showing the problem. Notification. ProfileID 1599 has a system identifier of 1126567, but one of the rights does not have a connector! How can I get both of these lines in a second query? (Above)