create cursor x1 ( i1 i ) for i = 1 to 10 insert into x1 values ( i ) endfor select x1.i1, x2.i1, x3.i1 ; from x1 ; left join x1 as x2 on x1.i1 != x2.i1 ; left join x1 as x3 on x1.i1 != x3.i1 and x2.i1 != x3.i1 ; into cursor ThePermutationsgiven 10 items in x1 the result will have 720 rows because it considers 1,2,3 and 1,3,2 and 2,1,3 and 2,3,1 and 3,1,2 and 3,2,1 as distinct permutations, for combinations you don't care about the order so any one of those 6 results is all you want.
select x1.i1 as i1, x2.i1 as i2, x3.i1 as i3 ; from x1 ; left join x1 as x2 on x1.i1 < x2.i1 ; left join x1 as x3 on x1.i1 < x3.i1 and x2.i1 < x3.i1 ; into cursor TheCombinations ; having ! isnull( i2 ) and ! isnull( i3 )This will eliminate the replications based on order and give you just the combinations.