请问为什么while @d<@a没有循环?declare
@a int ,@b int,@c int ,@d int ,@e int ,@f varchar(50) ,@g varchar(50)
create table #person
([idd] int IDENTITY (1, 1),
username varchar(50))
create table #windows
([idd] int IDENTITY (1, 1),
username varchar(50))
insert into #person (username )
select c_username from user_table
insert into #windows (username )
select username from windows
select @a=(select max(idd) from #person),@b=(select min(idd) from #person)
select @c=(select max(idd) from #windows),@d=(select min(idd) from #windows)
while @b<=@a
begin
select @f=(select username from #person where idd =@b)
while @d<=@c
begin
select @g=(select username from #windows where idd=@d)
select @e=(select count(*) from rights_table where c_username=@f and c_description=@g)
if @e=0
begin
insert into rights_table(c_username,c_description)values(@f,@g)
end
set @d=@d+1
end
set @b=@b+1
select @a,@b,@c,@d,@e,@f,@G
end
drop table #person
drop table #windows
@a int ,@b int,@c int ,@d int ,@e int ,@f varchar(50) ,@g varchar(50)
create table #person
([idd] int IDENTITY (1, 1),
username varchar(50))
create table #windows
([idd] int IDENTITY (1, 1),
username varchar(50))
insert into #person (username )
select c_username from user_table
insert into #windows (username )
select username from windows
select @a=(select max(idd) from #person),@b=(select min(idd) from #person)
select @c=(select max(idd) from #windows),@d=(select min(idd) from #windows)
while @b<=@a
begin
select @f=(select username from #person where idd =@b)
while @d<=@c
begin
select @g=(select username from #windows where idd=@d)
select @e=(select count(*) from rights_table where c_username=@f and c_description=@g)
if @e=0
begin
insert into rights_table(c_username,c_description)values(@f,@g)
end
set @d=@d+1
end
set @b=@b+1
select @a,@b,@c,@d,@e,@f,@G
end
drop table #person
drop table #windows
print 出来看一下
第一条得出的结果已经是非分@D>@C了
14 2 3 4 1 bo FrmColor
@a @b @c @d @e @f @g
是这个吧,不是while @d<=@a 吧
如果while @d<=@c 里没有执行,那就
在这句之前加个
print @d
print @c 看看
这样的话 @d<=@c 就不会循环了啊
14 2 3 4 1 bo FrmColor
@a @b @c @d @e @f @g说明:
@c=3
@d=4@d > @c
而 你的条件是这个: while @d<=@c 那while 里肯定不能运行啊
select @e=(select count(*) from rights_table where c_username=@f and c_description=@g) ----判定有没有记录
if @e=0
begin ----插入数据
end
set @d=@d+1 ---加1
end
怎么样也看不出问题在那里?