General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Get All Combinations
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
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only