Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Permutations (difficult one) Expand / Collapse
Author
Message
Posted Tuesday, January 28, 2014 7:30 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 8:01 PM
Points: 3,605, Visits: 5,198
oliveraustin (1/28/2014)
Ah ha, thought how to reduce the problem size down to 12 groups :)
Since the Roles with multiple groups consist of<=12 groups and the rest of the all I need to to do is filter the LDAP data and reduce it those entries that are in the set of groups that are part of multi group roles!...yippeee

Original problem is

A role consists of between 1 and x groups from a set of x groups.
A role can only have a particular group once.
A user may have more than one role
Example:

Role | Group
Helpdesk | Password Reset
Security | Password Reset,
Security | Enable User
Reception | Enable User
Reception | Disable User

The data I have is of the form

User | Group
SmithA | Password Reset
SmithA | Enable User
BloggsJ | Password Reset
MouseM | Enable User
MouseM | Disable User

From that I need to deduce the users have the following roles
User | Role
SmithA | Security
BloggsJ | Helpdesk
MouseM | Reception

Thanks


So does this mean you have a suitable solution now?



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1535693
Posted Tuesday, January 28, 2014 7:36 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 4:53 PM
Points: 936, Visits: 2,836
oliveraustin (1/28/2014)
Ah ha, thought how to reduce the problem size down to 12 groups :)
Since the Roles with multiple groups consist of<=12 groups and the rest of the all I need to to do is filter the LDAP data and reduce it those entries that are in the set of groups that are part of multi group roles!...yippeee

Original problem is

A role consists of between 1 and x groups from a set of x groups.
A role can only have a particular group once.
A user may have more than one role
Example:

Role | Group
Helpdesk | Password Reset
Security | Password Reset,
Security | Enable User
Reception | Enable User
Reception | Disable User

The data I have is of the form

User | Group
SmithA | Password Reset
SmithA | Enable User
BloggsJ | Password Reset
MouseM | Enable User
MouseM | Disable User

From that I need to deduce the users have the following roles
User | Role
SmithA | Security
BloggsJ | Helpdesk
MouseM | Reception

Thanks


I might be barking up the wrong tree completely here, but this may do what you want
with RoleGroup as (
SELECT *
FROM (VALUES
('Helpdesk' , 'Password Reset'),
('Security' , 'Password Reset'),
('Security', 'Enable User'),
('Reception' , 'Enable User'),
('Reception' , 'Disable User')
) rg(Role, Grp)
),
UserGroup as (
SELECT *
FROM (VALUES
('SmithA' , 'Password Reset'),
('SmithA' , 'Enable User'),
('BloggsJ' , 'Password Reset'),
('MouseM' , 'Enable User'),
('MouseM' , 'Disable User')
) ug(Usr, Grp)
),
potentialRoles AS (
SELECT usr, role, ug.grp
FROM (SELECT usr, grp, COUNT(*) OVER (PARTITION BY usr) gCount, ROW_NUMBER() OVER (PARTITION BY Usr ORDER BY grp) N FROM UserGroup) ug
INNER JOIN (SELECT role, grp, COUNT(*) OVER (PARTITION BY role) gCount, ROW_NUMBER() OVER (PARTITION BY role ORDER BY grp) N FROM RoleGroup) rg
ON ug.grp = rg.grp and ug.N = rg.N and ug.gCount = rg.gCount
)
SELECT usr, role
FROM potentialRoles
GROUP BY usr, role;

Post #1535694
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse