Я пытаюсь обновить поле Да / Нет (Запечатано) в таблице под названием [Активы] из подзапроса.
Результаты подзапроса содержат идентификатор из [Активы] и желаемый результат поля, которое будет обновлено.
Я пробовал несколько вариантов, в том числе предложения WHERE или FROM, но не смог достичь подходящего результата.
Ниже приведен базовый оператор обновления и подзапрос. Любой совет с благодарностью.
UPDATE [Assets] SET Sealed = IsSealed
SELECT y.Asset AS Asset,
IIF(y.TotalSeals>0,Yes,No) AS IsSealed
FROM (
SELECT x.Asset,
SUM(IIF(x.BOMTypes="Seal",1,0)) AS BOMSeals,
SUM(IIF(x.MatMovTypes="Seal",1,0)) AS MMSeals,
SUM(IIF(x.POTypes="Seal",1,0)) AS POSeals,
(BOMSeals + MMSeals + POSeals) AS TotalSeals
FROM (
SELECT [Data - Assets].ID AS Asset,
[Data - Inventory].Type AS BOMTypes,
NULL AS MatMovTypes, NULL AS POTypes, NULL AS TotalSeals
FROM [Data - Inventory] INNER JOIN ([Data - Assets] INNER JOIN [Data - BOM]
ON [Data - Assets].ID = [Data - BOM].Asset)
ON [Data - Inventory].ID = [Data - BOM].Component
UNION ALL
SELECT [Data - Assets].ID AS Asset, NULL AS BOMTypes,
[Data - Inventory].Type AS MatMovTypes,
NULL AS POTypes, NULL AS TotalSeals
FROM ([Data - Assets] INNER JOIN [Data - WO]
ON [Data - Assets].ID = [Data - WO].Asset)
INNER JOIN ([Data - Inventory] INNER JOIN [Data - MatMov]
ON [Data - Inventory].ID = [Data - MatMov].Component)
ON [Data - WO].ID = [Data - MatMov].WorkOrder
UNION ALL
SELECT [Data - Assets].ID AS Asset,
NULL AS BOMTypes, NULL AS MatMovTypes,
[Data - Inventory].Type AS POTypes, NULL AS TotalSeals
FROM ([Data - Assets] INNER JOIN [Data - WO]
ON [Data - Assets].ID = [Data - WO].Asset)
INNER JOIN ([Data - Inventory] INNER JOIN [Data - PO]
ON [Data - Inventory].ID = [Data - PO].Component)
ON [Data - WO].ID = [Data - PO].WorkOrder
) AS x
GROUP BY x.Asset
) AS y;