日期:2014-05-18 浏览次数:20495 次
insert 表2 select a.ID from 表1 as a,(select top 20 ID from syscolumns) as b where a.ID=a
------解决方案--------------------
双循环
declare @id varchar(10),@n int=1 ,@i int=1 while exists(select 1 from (select *,ROW_NUMBER() over(order by getdate()) rid from tb)a where rid=@n) begin select @id=id from tb where rid=@n while @i<=20 begin insert into b select id from a set @i = @i + 1 end set @n=@n+1 end
------解决方案--------------------
declare @id
declare @cursor_Insert cursor for
select Id from table1
open @cursor_Insert
fetch next from @cursor_Insert into @id
while @@FETCH_STATUS=0
begin
..插入20行数据.
fetch next from @cursor_Insert into @id
end
close @cursor_Insert
deallocate @cursor_Insert
------解决方案--------------------