我正在寻找以下更新查询的帮助。我正在尝试更新 provreg
表的最新更新的契约,但它似乎不正确。使用contractinfo表上的max(lastupdate)字段完成此更新的最佳方法是什么?
UPDATE provreg
SET ContractName = ci.ContractID,
ContractBegin = ci.ContractEff,
ContractEnd = ci.contractterm
FROM provreg pr
INNER JOIN Provider P ON pr.npi = p.npi
INNER JOIN Affiliation A ON a.provid = p.provid
INNER JOIN contractinfo ci ON ci.affiliationid = a.affiliationid
WHERE CI.CONTRACTED = 'Y'
AND ci.lastupdate = (SELECT MAX(lastupdate)
FROM PlanReport_QNXT_LA.dbo.contractinfo
WHERE contractid = ci.contractid)
1条答案
按热度按时间agyaoht71#
试试下面。