Using: SQL Server 2008 R2
My goal is to take a given integer (n) and select every permutation of integers with n bits in 2 columns, as below.
Given: n=4
Output:
ColA ColB
0 0
0 0
0 0
0 0
1 0
1 0
1 0
1 1
2 0
2 0
2 1
2 0
3 0
3 0
3 1
3 1
...
14 1
14 1
14 1
14 0
15 1
15 1
15 1
15 1
The output does not, repeat does NOT, need to be ordered, which may or may not make this easier. I do, however, need to be able to set n to any integer… but for the sake of runtime, let’s say it’ll be under 10.
Thanks in advance.
You might want to try this:
AllTheNumbers produces the numbers from 0 to 2^n-1, Bits produces bit numbers from 0 to @Bits – 1 and main part connects them and calculates bit value per position.