27,579
社区成员
发帖
与我相关
我的任务
分享
declare @tablename0 nvarchar(200), -- 来源表表名
@tablename1 nvarchar(200), -- 目标表表名
@tsql nvarchar(max)
declare ap scroll cursor for
select name from sys.tables where [过滤条件] --> 加where条件查询出所有目标表
open ap
fetch first from ap into @tablename1
while(@@fetch_status<>-1)
begin
select @tablename0=[转换规则] --> 将目标表表名(@tablename1)按转换规则得到来源表表名
-- 动态产生插入数据的insert语句,然后执行.
select @tsql=N'insert into '+@tablename1+N'([字段列表]) '
+N'select [字段列表] from '+@tablename0
exec(@tsql)
fetch next from ap into @tablename1
end
close ap
deallocate ap
insert into tablexxx (aa,bb,cc) select aa,bb,cc from tableooo
declare @tablename nvarchar(200),@tsql nvarchar(max)
declare ap scroll cursor for
select name from sys.tables
open ap
fetch first from ap into @tablename
while(@@fetch_status<>-1)
begin
-- 动态产生插入数据的insert语句,然后执行.
select @tsql=N'insert into '+@tablename+N'([字段列表]) '
+N'[字段的值]'
exec(@tsql)
fetch next from ap into @tablename
end
close ap
deallocate ap