1. Registered User
Join Date
Sep 2003
Posts
522

i am trying to set up a quick and dirty, but efficient way to calculate permutation and combination. anyone out there dealt with this?

2. Registered User
Join Date
Sep 2003
Posts
522
any takers?

3. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
The method depends on what kind of permutations you want to do.

Given N objects in X different positions, do you want to allow repetitions? Do you want to include permutations with less than X values?

There are formulas available that will calculate these. Excel actually has some good statistical functions that not only do the calculations, but the help file does a good job of explaining the formula used. You might run a couple test on a spreadsheet until you are sure what kind of permutation you want, and then port the formula from Excel's help file into a TSQL statement.

4. Registered User
Join Date
Sep 2003
Posts
522
ok, it's been awhile, and i barely passed it, but knowing the total number (9999), what is the n in this combination formula:

9999 = n! / (4!(n-4)!)

5. Registered User
Join Date
Sep 2003
Posts
522
never mind, it doesn't jive, back to the drawing board

6. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
N is the number of items, and I believe 4 is the number of locations.

N! is N Factorial, which SQL Server does not have as a standard function, but is simply 1*2*3*4*5...*N, so you could write the function easily enough.

7. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595