CREATE TABLE AB(
[a] int,
[b] int
)
GO
declare @a int
set @a = 1
declare @b int
set @b = 1
while @a < 10
begin
while @b<10
begin
insert into AB values
(@a,@b)
set @b+=1
end
set @a+=1
end
GO
select * from AB
本来想笑得结果是
1 1
1 2
1 3
.
.
.
1 9
2 1
.
.
2 9
.
.
.
9 1
.
.
.
9 9
可是结果只有
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
是不是循环写错了,求指点
------解决方案--------------------
因为第二个while第一次循环完后变成了9,然后外边开始第二次,这时候不给set 1 的话,@b 还是9