我正在使用SupplierA
中的详细信息更新SupplierB
。
SupplierB
包含供应商提供的每个订单,但是,当我插入SupplierA
时,我只想为每个供应商添加一个实例,因此 most recent
与订单相关的日期。
目前我正在做这样的事情;
UPDATE SupplierA
SET LastSupplyDate = (SELECT [DATE] FROM SupplierB AS SB WHERE SB.Supplier COLLATE DATABASE_DEFAULT = SupplierA.SupNumber COLLATE DATABASE_DEFAULT)
WHERE [Site] = 2
显然这会返回多个值,如何获得最新值,MAX()
是一个选项?我很欣赏任何想法/想法吗?
答案 0 :(得分:3)
SET LastSupplyDate = (SELECT MAX([DATE])...
答案 1 :(得分:1)
UPDATE SupplierA SET LastSupplyDate =
(
SELECT TOP 1 [DATE] FROM SupplierB AS SB
WHERE SB.Supplier
COLLATE DATABASE_DEFAULT = SupplierA.SupNumber COLLATE DATABASE_DEFAULT
ORDER BY [DATE] DESC
)
WHERE [Site] = 2
答案 2 :(得分:1)
UPDATE SupplierA
SET LastSupplyDate = (SELECT MAX([DATE]) FROM SupplierB AS SB WHERE SB.Supplier COLLATE DATABASE_DEFAULT = SupplierA.SupNumber COLLATE DATABASE_DEFAULT)
WHERE [Site] = 2