Perform update operations across libraries in SQL Server

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.