22,210
社区成员
发帖
与我相关
我的任务
分享
--先截出可以导入的内容,以加快游标速度
Select a.*,convert(datetime,convert(varchar(10),dDate,111)+' '+convert(varchar(10),dCreate,108),120) dNewCreate into #tmp09060501 from CA_UploadTmp a inner join ems_001..C b on a.ccricode=b.bh
where cUserId=@cUserId and iExId>=0 and bSelect=1 --and --and iSoType in ('CA','CD')
Update CA_UploadTmp set iExId=(case when iExId=0 or iExId=-1 then -1 else -2 end)
where cUserId=@cUserId and (not iId in (Select iId from #tmp09060501)) and dVaudit>=@dBDate and dVaudit<=@dEDate
declare tItem cursor for
SELECT iId,iSoType,cCriCode,iLinkId,cDeed,iExId,dNewCreate FROM #tmp09060501 --where cUserId=@cUserId and isnull(iExId,0)=0
open tItem
FETCH NEXT FROM tItem into @iId,@cVtype,@CriCode,@iLinkId,@cDeed,@iExId,@dNewCreate
WHILE (@@FETCH_STATUS <> -1) and (@@FETCH_STATUS <> -2)
BEGIN
-- if exists(Select bh from vw_jg_jbxx where bh=@CriCode)
-- begin
if @iExId=0 ----新的上传
begin
if @cVtype='CA' or @cVtype='CD'
begin
insert into ems_001..A(bh,rq,jf,kf,ljf,db,tk,tkmc,gj,spr,yhbh,lrsj)
Select cCriCode,dbo.uf_dt_GetYMDStr(isnull(dVAudit,dVDate)),0
,isnull(fScore,0)
,isnull(cast(dbo.uf_CA_GetAssAch(1,cCriCode,@dDate
,isnull(dVAudit,dVDate),'','') as numeric),0)
,dbo.uf_UI_GetCode2Ex('部门代码',cDeptCode),cRuleCode,cRuleName,cVPersonName,cVAudit
,dbo.uf_GetUserN2C2(cMarker),@dNewCreate from #tmp09060501 Where iId=@iId
--select @iNewId=id from ems_001..A where bh=@CriCode and lrsj=@dNewCreate
set @iNewId=@@IDENTITY
--写备注字段
Update ems_001..A set bz=@cDeed where Id=@iNewId
--(select top 1 isnull(cRuleName,'')+char(13)+cDeed from CA_UploadTmp where iId=@iId) where Id=@iNewId
--写ID回本系统的表中
update CA_UploadTmp set iUploadState=2,iExId=@iNewId where iId=@iId
if @cVtype='CA'
update CA_DailyVouchs set dUpLoadTime=GetDate(),iUpLoadState=2,iExId=@iNewId where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
else
update Ca_Daily set dUpLoadTime=GetDate(),iUpLoadState=2,iExId=@iNewId where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
set @iKF=@iKf+1
end
else
begin
insert into ems_001..B(bh,cbrq,pzrq,jclb,jcyy,db,yhbh,lrsj,mj,sfsy)
Select cCriCode,dbo.uf_dt_GetYMDStr(dVDate),dbo.uf_dt_GetYMDStr(isnull(dVAudit,dVDate))
-- dbo.uf_UI_GetCode2Ex('类别',cEncCode)
,dbo.uf_CA_GetEncCode(cEncCode,1)
,'符合规定第'+cRuleCode+'条',dbo.uf_UI_GetCode2Ex('部门代码',cDeptCode)
,dbo.uf_GetUserN2C2(cMarker),@dNewCreate,0,1 from #tmp09060501 Where iId=@iId
select @iNewId=id from ems_001..B where bh=@CriCode and lrsj=@dNewCreate
--set @iNewId=@@IDENTITY
--写回备注字段
--Update ems_001..B set jcjs=(Select isnull(cRuleName,'')+' '+@cDeed from #tmp09060501 where iId=@iId) where Id=@iNewId
Update ems_001..B set jcjs=@cDeed where Id=@iNewId
--写ID回本系统的表中
update CA_UploadTmp set iUploadState=2,iExId=@iNewId where iId=@iId
if @cVtype='EA'
update Ca_EncBatchVouchs set dUpLoadTime=GetDate(),iUpLoadState=2,iExId=@iNewId where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
else
update Ca_EncVouch set dUpLoadTime=GetDate(),iUpLoadState=2,iExId=@iNewId where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
set @iJF=@iJF+1
end
end
else if @iExId>0 ----重新上传
begin
if @cVtype='CA' or @cVtype='CD'
begin
Update a set bh=cCriCode,jf=0
,rq=dbo.uf_dt_GetYMDStr(isnull(dVAudit,dVDate))
,kf=isnull(fScore,0)
,ljf=isnull(cast(dbo.uf_CA_GetAssAch(1,cCriCode,@dDate,isnull(dVAudit,dVDate),'','') as numeric),0)
,db=dbo.uf_UI_GetCode2Ex('部门代码',cDeptCode)
,tk=cRuleCode
,tkmc=cRuleName
,gj=cVPersonName
,spr=cVAudit
,yhbh=dbo.uf_GetUserN2C2(cMarker)
,lrsj=@dNewCreate
,bz=@cDeed
from ems_001..A a inner join #tmp09060501 b on a.Id=b.iExId
where b.iId=@iId
--写ID回本系统的表中
update CA_UploadTmp set iUploadState=2 where iId=@iId
if @cVtype='CA'
update CA_DailyVouchs set dUpLoadTime=GetDate(),iUpLoadState=2 where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
else
update Ca_Daily set dUpLoadTime=GetDate(),iUpLoadState=2 where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
set @iRKF=@iRKF+1
end
--行政奖罚---------------------------------
else
begin
Update a set bh=cCriCode
,cbrq=dbo.uf_dt_GetYMDStr(dVDate)
,pzrq=dbo.uf_dt_GetYMDStr(isnull(dVAudit,dVDate))
,jclb=dbo.uf_CA_GetEncCode(cEncCode,1) -- dbo.uf_UI_GetCode2Ex('奖罚类别',cEncCode)
,jcyy='符合考核规定第'+cRuleCode+'条'
,jcjs=@cDeed --,jcjs=(isnull(cRuleName,'')+' '+@cDeed)
,db=dbo.uf_UI_GetCode2Ex('部门代码',cDeptCode)
,yhbh=dbo.uf_GetUserN2C2(cMarker)
,lrsj=@dNewCreate,mj=0,sfsy=1
from ems_001..B a inner join #tmp09060501 b on a.Id=b.iExId
where b.iId=@iId
--写ID回本系统的表中
update CA_UploadTmp set iUploadState=2 where iId=@iId
if @cVtype='EA'
update Ca_EncBatchVouchs set dUpLoadTime=GetDate(),iUpLoadState=2 where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
else
update Ca_EncVouch set dUpLoadTime=GetDate(),iUpLoadState=2 where iId=@iLinkId --(select iLinkId from CA_UploadTmp Where iId=@iId )
set @iRJF=@iRJF+1
end
end
FETCH NEXT FROM tItem into @iId,@cVtype,@CriCode,@iLinkId,@cDeed,@iExId,@dNewCreate
END
CLOSE tItem
DEALLOCATE tItem