标签:pen font 分享图片 src not alt 增量同步 eid har
在公司实习,需要实现将一张表数据定时插入到另一张表
这里用到了游标和sql server的作业
declare @subMark int, @currentMark varchar(32), @name varchar(32), @capitalspec varchar(100); set @subMark=(select substring(max(mark),3,7)+1 from CptCapital where mark like ‘sc04%‘ and len(mark)=8) -- 声明游标 DECLARE c_offOrdMacConfigZhb CURSOR FAST_FORWARD FOR select F_124 as name,(F_125+FModel+Fname) as capitalspec from offOrdMacConfigZhb; --打开游标 open c_offOrdMacConfigZhb; --取第一条记录 FETCH NEXT FROM c_offOrdMacConfigZhb INTO @name,@capitalspec; WHILE @@FETCH_STATUS=0 begin --不存在才执行插入操作 if not exists(select * from CptCapital where name=@name and capitalspec=@capitalspec and isdata=1) begin set @currentMark=‘SC0‘+convert(varchar,@subMark); insert into CptCapital(mark,name,departmentid,resourceid,sptcount,currencyid,capitalspec,capitaltypeid,capitalgroupid,unitid,isdata)values(@currentMark,@name,859,8274,1,1,@capitalspec,1,30,1,1); set @subMark=@subMark+1; end -- 取下一条记录 FETCH NEXT FROM c_offOrdMacConfigZhb INTO @name,@capitalspec; end -- 关闭游标 CLOSE c_offOrdMacConfigZhb; -- 释放游标 DEALLOCATE c_offOrdMacConfigZhb;
在这里学会了游标的使用
标签:pen font 分享图片 src not alt 增量同步 eid har
原文地址:https://www.cnblogs.com/goxcheer/p/8761486.html