Reputation: 1647
Hopefully an easy question: I have two sql
tables Items
and BillOfMaterials
Items
has fields ItemID
and ItemCategory
BillOfMaterials
has fields ItemID
and ComponentItemID
How can I do an UPDATE
on BillOfMaterials
to change the ComponentItemID
where the ItemID
has a certain category? e.g.
UPDATE BillOfMaterials
SET ComponentItemID = dbo.GetNewItemID(ComponentItemID)
WHERE ItemCategory = 1 <-- Magic join here to pull in ItemCategory
Upvotes: 0
Views: 55
Reputation: 6866
This should do it:
UPDATE b
SET ComponentItemID = dbo.GetNewItemID(ComponentItemID)
FROM BillOfMaterials b
INNER JOIN Items I on I.ItemID = b.ComponentItemID
WHERE i.ItemCategory = 1
Upvotes: 4