Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get All Combinations
Message
De
19/01/2016 14:31:15
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Get All Combinations
Divers
Thread ID:
01629948
Message ID:
01629948
Vues:
57
I have a table with 5 values
A1
B2
C3
D4
E5

Problem 1
I need to be able to get all possible 2 value combinations of these values
A1,B2
A1,C3
A1,D4
A1,E5
B2,C3
B2,D3
B2,E4
C3,D4
C3,E5
D4,E5

Problem 2
I need to be able to get all possible 3 value combinations
A1,B2,C3
A1,B2,D4
A1,B2,E5
A1,C3,D4
A1,C3,E5
A1,D4,E5
B1,C3,D4
B2,C3,E5
B2,D4,E5
C3,D4,E5

Real Problem
A function/procedure/etc that can get all possible combination of length 2 through N

MYPROC @table, 3 -- all results for combinatins of 2 or 3
A1,B2
A1,C3
A1,D4
A1,E5
B2,C3
B2,D3
B2,E4
C3,D4
C3,E5
D4,E5
A1,B2,C3
A1,B2,D4
A1,B2,E5
A1,C3,D4
A1,C3,E5
A1,D4,E5
B1,C3,D4
B2,C3,E5
B2,D4,E5
C3,D4,E5

I've done something like this in VFP but I don't think my solution is transportable.

Google didn't show (or at least I didn't find) any examples of what I need and I am unable to figure out how to modify what came close.

If somebody has done something like this I can really use some guidance.

Thanks.....................Rich
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform