Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Permutations (difficult one)

$
0
0

Hi,
We're tyring to find the best way to solve the following, hope you can help please.
We have a fairly large table of users (2500+) and the users belong to 1 or more groups (at the moment the max number of groups a user is in is 32 but it changes daily).
A sample data set looks like:
Usr     | Grp
==============
SmithA  | GrpA
SmithA  | GrpB
MouseM  | GrpD
MouseM  | GrpB
MouseM  | GrpC

The result set we need would be:
SmithA | GrpA
SmithA | GrpB
SmithA | GrpA,GrpB
MouseM | GrpB
MouseM | GrpC
MouseM | GrpD
MouseM | GrpB,GrpC
MouseM | GrpB,GrpD
MouseM | GrpC,GrpD
MouseM | GrpB,GrpC,GrpD

Note the alphabetical order of the grps - it's not particularly imporant but if they aren't sorted alphabetical then we'd need all combinations.

Any ideas please?



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>