日期:2014-05-18 浏览次数:20456 次
declare @a int set @a =1 while @a<11 begin --your coding print @a set @a = @a+1 end
------解决方案--------------------
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循环的