中国开发网: 论坛: 数据库: 贴子 811094
haitao
以n条记录(1个字段/条)代替1条记录(nxn个字段),条件简化,效率高了很多!!
--该表保存结果
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 行受影响)
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录