收到说明聚合的错误可能不会出现在UPDATE语句的集合列表中。有什么想法吗?
UPDATE STOCK SET STOCK.LPURCHDATE = MAX(INVTRANS.TRANS_DATE)
FROM STOCK
INNER JOIN INVTRANS ON STOCK.NUMBER = INVTRANS.NUMBER
WHERE INVTRANS.NOTATION <> 'Product Merging' AND
(INVTRANS.TRANSTYPE = 'D' OR INVTRANS.TRANSTYPE = 'A')
答案 0 :(得分:0)
试试这个
UPDATE STOCK SET STOCK.LPURCHDATE = (select MAX(INVTRANS.TRANS_DATE) FROM INVTRANS
WHERE INVTRANS.NOTATION <> 'Product Merging'
AND INVTRANS.TRANSTYPE IN('D','A')
AND STOCK.NUMBER = INVTRANS.NUMBER)
或强>
;with tmp as(
SELECT STOCK.NUMBER, MAX(INVTRANS.TRANS_DATE) MX
FROM STOCK
INNER JOIN INVTRANS ON STOCK.NUMBER = INVTRANS.NUMBER
WHERE INVTRANS.NOTATION <> 'Product Merging' AND
(INVTRANS.TRANSTYPE = 'D' OR INVTRANS.TRANSTYPE = 'A')
)
UPDATE STOCK SET STOCK.LPURCHDATE = MX
FROM STOCK
INNER JOIN TMP ON STOCK.NUMBER = TMP.NUMBER