我有一个每天运行的存储过程来为我们的业务提取库存号。我被要求更新存储过程以获取已在部件上写入采购订单的某些行的信息。例如
Tbl A(本地服务器)
partnumber poNumber ReceivedDate PartStatus
Tbl B(链接服务器)
poNumber partnumber ReceivedDate
我只需查看TblA.PartStatus = "Shipped" AND tblA.poNumber = tblB.poNumber
的项目,然后查看TblB.ReceivedDate
是否为空。
如果TblB.ReceivedDate
不为空,我需要设置TblA.ReceivedDate = TblB.ReceivedDate
如何将其设置为遍历表格或执行单个连接语句以使其更快?
答案 0 :(得分:0)
一种方法是:
UPDATE a SET a.ReceivedDate = b.ReceivedDate
FROM tblA AS a
INNER JOIN tblB AS b
ON (a.poNumber = b.poNumber AND a.partNumber = b.partNumber AND a.partStatus = 'Shipped' AND b.ReceivedDate IS NOT NULL)