DECLARE @DeptName varchar, @LoadCount float, @TransCount float, @HisLoad float, @HisTrans float, @Status varchar (50), @PushDate datetime, @EditDate datetime declare @date datetime set @date =convert (Datetime,convert (Varchar,getdate ()- 2,23)) UPDATE YSJ_Backup.dbo.RP_BusTransInfo set Rbi_loadcount=a.loadcount, Rbi_transcount=a.transcount,rbi_hisload =a.hisload,rbi_histrans=a.histrans, Rbi_status=a.rbi_status,rbi_editdate=getdate () from YSJ_Backup.dbo.RP_ Bustransinfo INNER JOIN (select A.rpb_name,a.loadcount,a.transcount,a.hisload,a.histrans,a.rbi_status,a.pushdate,a . Editdate from (SELECT rp_branchtrans.rpb_name, ISNULL (bus.rbi_loadcount,0) as Loadcount,isnull (bus.rbi_transcount,0) As Transcount,isnull (bus.rbi_hisload,0) as Hisload, ISNULL (bus.rbi_histrans,0) as HISTRANS,BUS.RBI_STATUS,RPF. Rfi_date pushdate,getdate () editdate from Rp_bustransinfo Bus INNER JOIN Rp_branchtrans on BUS.RPB_ID=RP_BRANCHTRANS.RPB _id INNER JOIN rp_forminstance RPF on bus.rfi_id = RPF. rfi_id INNER JOIN Rp_foRmlist FL on fl. rfl_id = RPF. rfl_id WHERE FL. Rfl_code = (case when (EXISTS) (SELECT rfi_id from rp_forminstance WHERE rfl_id = ' RFL20090410001 ' and rfi_date = RPF. Rfi_date and rfi_state = ' 1 ') Then ' D203 ' ELSE ' D103 ' END ' and RPF. Rfi_date between @date -30 and @date and RPF. Rfi_state= ' 1 ') as a inner join YSJ_Backup.dbo.RP_BusTransInfo B on A.rpb_name=b.rbi_department and A.pushdate=b.rbi_push Date where A.loadcount!=b.rbi_loadcount or A.transcount!=b.rbi_transcount or A.hisload!=b.rbi_hisload or a.HisTrans!=b . Rbi_histrans or A.rbi_status!=b.rbi_status and a.pushdate between @date -30 and @date) as a on A.PUSHDATE=YSJ_BACKUP.DBO.R P_bustransinfo.rbi_pushdate and A.rpb_name=ysj_backup.dbo.rp_bustransinfo.rbi_department
Perform update operations across libraries in SQL Server