游标批量插入数据

--开启游标遍历查询所需信息
declare @code varchar(50)
declare my_test cursor for --定义游标
select DISTINCT Files[字段] from 【源表名】

--打开游标遍历循环条码
open my_test

while @@FETCH_STATUS = 0
BEGIN
fetch next from my_test into @code
--查询
INSERT INTO 【目的表名】(Files1,Files2,Files3 )
VALUES(@code,'',getdate())
end
close my_test
--释放游标
deallocate my_test

posted @ 2016-09-13 14:38  向往田园  阅读(1414)  评论(0编辑  收藏  举报