update a
set a.CusCode =b.StandardCustomerCode
from SFA_VisitExtend as a
inner join
(
select etl.StandardCustomerCode,vct.DistributorCode, vct.ComCode from agrodb.dbo.ETL_StoreCompare etl
inner join Sfa_Uat.dbo.V_CUS_table vct
on vct.DistributorCode = etl.DISTRIBUTOR AND vct.ComCode =etl.CUSTOMER_CODE_BACKUP
where vct.ComCode is not null and vct.DistributorCode is not null and etl.StandardCustomerCode is not null and vct.Flag='Y'
) as b
on a.DisCode=b.DistributorCode
and a.CusCode=b.ComCode
update a
set a.CtmCode =b.StandardCustomerCode
from Visit_CycleRouteDetail as a
inner join
(
select etl.StandardCustomerCode,vct.DistributorCode, vct.ComCode from agrodb.dbo.ETL_StoreCompare etl
inner join Sfa_Uat.dbo.V_CUS_table vct
on vct.DistributorCode = etl.DISTRIBUTOR AND vct.ComCode =etl.CUSTOMER_CODE_BACKUP
where vct.ComCode is not null and vct.DistributorCode is not null and etl.StandardCustomerCode is not null and vct.Flag='Y'
) as b
on a.DisCode=b.DistributorCode
and a.CtmCode=b.ComCode
update a
set a.ComCode =b.StandardCustomerCode
from V_CUS_table as a
inner join
(
select etl.StandardCustomerCode,vct.DistributorCode, vct.ComCode from agrodb.dbo.ETL_StoreCompare etl
inner join Sfa_Uat.dbo.V_CUS_table vct
on vct.DistributorCode = etl.DISTRIBUTOR AND vct.ComCode =etl.CUSTOMER_CODE_BACKUP
where vct.ComCode is not null and vct.DistributorCode is not null and etl.StandardCustomerCode is not null and vct.Flag='Y'
) as b
on a.DistributorCode=b.DistributorCode
and a.ComCode=b.ComCode