使用JOIN for WHERE子句进行SQL更新

使用JOIN for WHERE子句进行SQL更新,sql,sql-server,Sql,Sql Server,希望是一个简单的问题:我有两个sql表Items和BillOfMaterials Items具有字段ItemID和itemcegory BillOfMaterials具有字段ItemID和ComponentItemID 如何在BillOfMaterials上执行UPDATE以更改ComponentItemID,其中ItemID具有特定类别?e、 g UPDATE BillOfMaterials SET ComponentItemID = dbo.GetNewItemID(ComponentIte

希望是一个简单的问题:我有两个
sql
Items
BillOfMaterials

Items
具有字段
ItemID
itemcegory
BillOfMaterials
具有字段
ItemID
ComponentItemID

如何在
BillOfMaterials
上执行
UPDATE
以更改
ComponentItemID
,其中
ItemID
具有特定类别?e、 g

UPDATE BillOfMaterials
SET ComponentItemID = dbo.GetNewItemID(ComponentItemID)
WHERE ItemCategory = 1 <-- Magic join here to pull in ItemCategory
更新物料清单
设置ComponentItemID=dbo.GetNewItemID(ComponentItemID)
其中itemcegory=1应该这样做:

UPDATE b
SET ComponentItemID = dbo.GetNewItemID(ComponentItemID)
FROM BillOfMaterials b
INNER JOIN Items I on I.ItemID = b.ComponentItemID
WHERE i.ItemCategory = 1
这应该做到:

UPDATE b
SET ComponentItemID = dbo.GetNewItemID(ComponentItemID)
FROM BillOfMaterials b
INNER JOIN Items I on I.ItemID = b.ComponentItemID
WHERE i.ItemCategory = 1

可能重复的标量函数,请小心标量函数。它们可能会导致严重的性能问题。可能会重复标量函数,请小心标量函数。它们可能是严重的性能问题。这似乎已经完成了所有记录,而不仅仅是类别1Ahh,忽略我,我需要加入b.ComponentItemID而不是b.ItemID,但这很好。谢谢,因为它似乎已经完成了所有记录,不仅仅是类别1Ahh,忽略我,我需要加入b.ComponentItemID而不是b.ItemID,但这很好。谢谢你,贝库兹