新手提问,for问题
存储过程里怎么for 循环 添加另一张表的数据啊
[解决办法]
declare @i as int
declare @j as int
set @i = 1
set @j = 100
while @i <= @j
begin
print @i
set @i = @i + 1
end
[解决办法]
你要實現什麽功能具體的要求說出來
[解决办法]
如果能一次提取数据,可直接使用insert into
insert into tb1(col1,col2...) select col1,col2,... from tb2 where ...
[解决办法]
mssql 里没有 for 循环的
[解决办法]
写循环使用while
declare @a intset @a =1while @a<11begin--your codingprint @aset @a = @a+1end
[解决办法]
insert Table1(dd) select aa from table2
[解决办法]
用游标吧:
declare @aa varchar(50)
declare cur cursor for select aa from table2
open cur
fetch next into @aa
while(@@fetch_status=0)
begin
insert into table1 (cc,dd) values (11,@aa)
fetch next into @aa
end
close cur
deallocate cur
[解决办法]
或者:
insert into Table1(cc,dd) select 11,aa from table2
[解决办法]
用游标吧:
declare @aa varchar(50)
declare cur cursor LOCAL STATIC for
select aa from table2
open cur
while(0=0)
begin
fetch next into @aa
IF @@fetch_status <> 0
break;
insert into table1 (cc,dd) values (11,@aa)
end
close cur
deallocate cur
[解决办法]
insert T1(dd) select aa from T2--就可以
[解决办法]
insert T1(cc,dd) select 11,aa from T2--就可以
[解决办法]
sql 是用 while begin and 代替for循环的