SQL 與 Informix 關聯資料更新

update mrp.pmc_file set pmc02=b.VendorCode
,pmc03=b.VendorStName collate Chinese_PRC_CI_AS
,pmc04=b.VendorFullName collate Chinese_PRC_CI_AS
FROM mrp.pmc_file a,(
select * from OpenQuery(KSTiptop,'
select a.pmn04,max(b.pmm09) VendorCode,max(c.pmc03) VendorStName,max(c.pmc081) VendorFullName
from pmn_file a,pmm_file b,pmc_file c
where a.pmn01=b.pmm01 and b.pmm09=c.pmc01
and b.pmm04=(select max(pmm04) from pmm_file s,pmn_file t where s.pmm01=t.pmn01 and t.pmn04=a.pmn04
and s.pmm04 between today-30 and today
group by t.pmn04)
and b.pmm04 between today-30 and today
group by a.pmn04')) b where a.pmc01=b.pmn04 collate Chinese_PRC_CI_AS

insert into mrp.pmc_file
select pmn04,VendorCode,VendorStName collate Chinese_PRC_CI_AS
,VendorFullName collate Chinese_PRC_CI_AS
from OpenQuery(KSTiptop,'
select a.pmn04,max(b.pmm09) VendorCode,max(c.pmc03) VendorStName,max(c.pmc081) VendorFullName
from pmn_file a,pmm_file b,pmc_file c
where a.pmn01=b.pmm01 and b.pmm09=c.pmc01
and b.pmm04=(select max(pmm04) from pmm_file s,pmn_file t where s.pmm01=t.pmn01 and t.pmn04=a.pmn04
and s.pmm04 between today-30 and today
group by t.pmn04)
and b.pmm04 between today-30 and today
group by a.pmn04') a
where not exists (select '*' from mrp.pmc_file t where t.pmc01=a.pmn04 collate Chinese_PRC_CI_AS)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值