--该表保存结果
declare @c table (c1 tinyint, c2 tinyint, c3 tinyint, c4 tinyint, c5 tinyint, c6 tinyint, c7 tinyint, c8 tinyint)
--该表做笛卡尔积
declare @t table (p tinyint)
insert into @t
select 1
union select 2
union select 3
union select 4
union select 5
union select 6
union select 7
union select 8
insert @c
select
--count(*)
--top 100
*
from @t t1
cross join @t t2
cross join @t t3
cross join @t t4
cross join @t t5
cross join @t t6
cross join @t t7
cross join @t t8
where 1=1
--竖
and t1.p<>t2.p and t1.p<>t3.p and t1.p<>t4.p and t1.p<>t5.p and t1.p<>t6.p and t1.p<>t7.p and t1.p<>t8.p
and t2.p<>t3.p and t2.p<>t4.p and t2.p<>t5.p and t2.p<>t6.p and t2.p<>t7.p and t2.p<>t8.p
and t3.p<>t4.p and t3.p<>t5.p and t3.p<>t6.p and t3.p<>t7.p and t3.p<>t8.p
and t4.p<>t5.p and t4.p<>t6.p and t4.p<>t7.p and t4.p<>t8.p
and t5.p<>t6.p and t5.p<>t7.p and t5.p<>t8.p
and t6.p<>t7.p and t6.p<>t8.p
and t7.p<>t8.p
--右斜
and t1.p<>t2.p-1 and t1.p<>t3.p-2 and t1.p<>t4.p-3 and t1.p<>t5.p-4 and t1.p<>t6.p-5 and t1.p<>t7.p-6 and t1.p<>t8.p-7
and t2.p<>t3.p-1 and t2.p<>t4.p-2 and t2.p<>t5.p-3 and t2.p<>t6.p-4 and t2.p<>t7.p-5 and t2.p<>t8.p-6
and t3.p<>t4.p-1 and t3.p<>t5.p-2 and t3.p<>t6.p-3 and t3.p<>t7.p-4 and t3.p<>t8.p-5
and t4.p<>t5.p-1 and t4.p<>t6.p-2 and t4.p<>t7.p-3 and t4.p<>t8.p-4
and t5.p<>t6.p-1 and t5.p<>t7.p-2 and t5.p<>t8.p-3
and t6.p<>t7.p-1 and t6.p<>t8.p-2
and t7.p<>t8.p-1
--左斜
and t1.p<>t2.p+1 and t1.p<>t3.p+2 and t1.p<>t4.p+3 and t1.p<>t5.p+4 and t1.p<>t6.p+5 and t1.p<>t7.p+6 and t1.p<>t8.p+7
and t2.p<>t3.p+1 and t2.p<>t4.p+2 and t2.p<>t5.p+3 and t2.p<>t6.p+4 and t2.p<>t7.p+5 and t2.p<>t8.p+6
and t3.p<>t4.p+1 and t3.p<>t5.p+2 and t3.p<>t6.p+3 and t3.p<>t7.p+4 and t3.p<>t8.p+5
and t4.p<>t5.p+1 and t4.p<>t6.p+2 and t4.p<>t7.p+3 and t4.p<>t8.p+4
and t5.p<>t6.p+1 and t5.p<>t7.p+2 and t5.p<>t8.p+3
and t6.p<>t7.p+1 and t6.p<>t8.p+2
and t7.p<>t8.p+1
declare @n int
set @n=8
select ''
+char(13)+REPLACE(space(c1-1),' ','.')+'#'+REPLACE(space(@n-c1),' ','.')
+char(13)+REPLACE(space(c2-1),' ','.')+'#'+REPLACE(space(@n-c2),' ','.')
+char(13)+REPLACE(space(c3-1),' ','.')+'#'+REPLACE(space(@n-c3),' ','.')
+char(13)+REPLACE(space(c4-1),' ','.')+'#'+REPLACE(space(@n-c4),' ','.')
+char(13)+REPLACE(space(c5-1),' ','.')+'#'+REPLACE(space(@n-c5),' ','.')
+char(13)+REPLACE(space(c6-1),' ','.')+'#'+REPLACE(space(@n-c6),' ','.')
+char(13)+REPLACE(space(c7-1),' ','.')+'#'+REPLACE(space(@n-c7),' ','.')
+char(13)+REPLACE(space(c8-1),' ','.')+'#'+REPLACE(space(@n-c8),' ','.')
+char(13)+space(10)+char(13)
from @c
——结果:
(8 行受影响)
(92 行受影响)
.#......
.....#..
#.......
......#.
...#....
.......#
..#.....
....#...
...#....
......#.
#.......
.......#
....#...
.#......
.....#..
..#.....
...#....
.......#
#.......
....#...
......#.
.#......
.....#..
..#.....
...#....
.......#
#.......
..#.....
.....#..
.#......
......#.
....#...
...#....
.....#..
#.......
....#...
.#......
.......#
..#.....
......#.
....#...
......#.
#.......
..#.....
.......#
.....#..
...#....
.#......
....#...
......#.
#.......
...#....
.#......
.......#
.....#..
..#.....
....#...
..#.....
#.......
......#.
.#......
.......#
.....#..
...#....
....#...
..#.....
#.......
.....#..
.......#
.#......
...#....
......#.
.....#..
...#....
#.......
....#...
.......#
.#......
......#.
..#.....
.....#..
..#.....
#.......
......#.
....#...
.......#
.#......
...#....
.....#..
..#.....
#.......
.......#
...#....
.#......
......#.
....#...
.....#..
..#.....
#.......
.......#
....#...
.#......
...#....
......#.
......#.
..#.....
#.......
.....#..
.......#
....#...
.#......
...#....
.......#
..#.....
#.......
.....#..
.#......
....#...
......#.
...#....
.......#
...#....
#.......
..#.....
.....#..
.#......
......#.
....#...
..#.....
....#...
.#......
.......#
.....#..
...#....
......#.
#.......
..#.....
.....#..
.#......
....#...
.......#
#.......
......#.
...#....
..#.....
.....#..
.#......
......#.
....#...
#.......
.......#
...#....
..#.....
......#.
.#......
.......#
.....#..
...#....
#.......
....#...
..#.....
.....#..
.#......
......#.
#.......
...#....
.......#
....#...
..#.....
......#.
.#......
.......#
....#...
#.......
...#....
.....#..
..#.....
....#...
.#......
.......#
#.......
......#.
...#....
.....#..
....#...
......#.
.#......
.....#..
..#.....
#.......
.......#
...#....
....#...
......#.
.#......
...#....
.......#
#.......
..#.....
.....#..
....#...
......#.
.#......
.....#..
..#.....
#.......
...#....
.......#
.....#..
...#....
.#......
.......#
....#...
......#.
#.......
..#.....
.....#..
.......#
.#......
...#....
#.......
......#.
....#...
..#.....
......#.
...#....
.#......
.......#
.....#..
#.......
..#.....
....#...
......#.
...#....
.#......
....#...
.......#
#.......
..#.....
.....#..
.#......
......#.
..#.....
.....#..
.......#
....#...
#.......
...#....
...#....
......#.
..#.....
.......#
.#......
....#...
#.......
.....#..
......#.
....#...
..#.....
#.......
.....#..
.......#
.#......
...#....
......#.
#.......
..#.....
.......#
.....#..
...#....
.#......
....#...
#.......
......#.
...#....
.....#..
.......#
.#......
....#...
..#.....
..#.....
.....#..
...#....
.#......
.......#
....#...
......#.
#.......
..#.....
.....#..
...#....
#.......
.......#
....#...
......#.
.#......
..#.....
.......#
...#....
......#.
#.......
.....#..
.#......
....#...
....#...
.#......
...#....
......#.
..#.....
.......#
.....#..
#.......
....#...
......#.
...#....
#.......
..#.....
.......#
.....#..
.#......
....#...
.......#
...#....
#.......
......#.
.#......
.....#..
..#.....
....#...
#.......
...#....
.....#..
.......#
.#......
......#.
..#.....
....#...
.#......
...#....
.....#..
.......#
..#.....
#.......
......#.
....#...
.......#
...#....
#.......
..#.....
.....#..
.#......
......#.
......#.
.#......
...#....
#.......
.......#
....#...
..#.....
.....#..
.......#
.#......
...#....
#.......
......#.
....#...
..#.....
.....#..
#.......
......#.
....#...
.......#
.#......
...#....
.....#..
..#.....
.#......
......#.
....#...
.......#
#.......
...#....
.....#..
..#.....
...#....
#.......
....#...
.......#
.....#..
..#.....
......#.
.#......
...#....
......#.
....#...
..#.....
#.......
.....#..
.......#
.#......
...#....
.......#
....#...
..#.....
#.......
......#.
.#......
.....#..
...#....
#.......
....#...
.......#
.#......
......#.
..#.....
.....#..
...#....
.#......
....#...
.......#
.....#..
#.......
..#.....
......#.
...#....
......#.
....#...
.#......
.....#..
#.......
..#.....
.......#
.....#..
#.......
....#...
.#......
.......#
..#.....
......#.
...#....
.....#..
..#.....
....#...
.......#
#.......
...#....
.#......
......#.
.....#..
..#.....
....#...
......#.
#.......
...#....
.#......
.......#
.......#
.#......
....#...
..#.....
#.......
......#.
...#....
.....#..
.#......
.......#
.....#..
#.......
..#.....
....#...
......#.
...#....
.#......
...#....
.....#..
.......#
..#.....
#.......
......#.
....#...
....#...
.#......
.....#..
#.......
......#.
...#....
.......#
..#.....
......#.
.#......
.....#..
..#.....
#.......
...#....
.......#
....#...
.#......
....#...
......#.
...#....
#.......
.......#
.....#..
..#.....
.#......
....#...
......#.
#.......
..#.....
.......#
.....#..
...#....
..#.....
#.......
......#.
....#...
.......#
.#......
...#....
.....#..
..#.....
....#...
......#.
#.......
...#....
.#......
.......#
.....#..
...#....
.#......
......#.
..#.....
.....#..
.......#
....#...
#.......
...#....
.#......
......#.
....#...
#.......
.......#
.....#..
..#.....
...#....
.#......
......#.
..#.....
.....#..
.......#
#.......
....#...
.....#..
...#....
......#.
#.......
.......#
.#......
....#...
..#.....
.....#..
.#......
......#.
#.......
...#....
.......#
....#...
..#.....
.....#..
..#.....
......#.
.#......
.......#
....#...
#.......
...#....
.....#..
.#......
......#.
#.......
..#.....
....#...
.......#
...#....
.....#..
..#.....
......#.
.#......
...#....
.......#
#.......
....#...
.....#..
..#.....
......#.
...#....
#.......
.......#
.#......
....#...
.....#..
...#....
......#.
#.......
..#.....
....#...
.#......
.......#
#.......
....#...
.......#
.....#..
..#.....
......#.
.#......
...#....
#.......
.....#..
.......#
..#.....
......#.
...#....
.#......
....#...
.#......
.....#..
.......#
..#.....
#.......
...#....
......#.
....#...
..#.....
.....#..
.......#
#.......
...#....
......#.
....#...
.#......
..#.....
.....#..
.......#
#.......
....#...
......#.
.#......
...#....
..#.....
.....#..
.......#
.#......
...#....
#.......
......#.
....#...
..#.....
....#...
.......#
...#....
#.......
......#.
.#......
.....#..
...#....
.....#..
.......#
..#.....
#.......
......#.
....#...
.#......
...#....
.....#..
.......#
.#......
......#.
#.......
..#.....
....#...
...#....
.#......
.......#
....#...
......#.
#.......
..#.....
.....#..
...#....
.#......
.......#
.....#..
#.......
..#.....
....#...
......#.
....#...
..#.....
.......#
...#....
......#.
#.......
.....#..
.#......
....#...
#.......
.......#
.....#..
..#.....
......#.
.#......
...#....
....#...
#.......
.......#
...#....
.#......
......#.
..#.....
.....#..
....#...
.#......
.......#
#.......
...#....
......#.
..#.....
.....#..
......#.
..#.....
.......#
.#......
....#...
#.......
.....#..
...#....
(92 行受影响)