问题解决了,非常感谢你们。 似乎如果没有update()排除包含列"同步"的所有更新。虽然我最初的意图是试图仅在该列上排除更新。
我已经创建了一个更新触发器来审核表中发生的任何更新。 我刚刚意识到,如果我从变量更新,它将不会触发触发器。有解决方案吗?
触发器:
CREATE trigger [dbo].[update_trigger]
On [dbo].[material_current]
For Update
as
if NOT UPDATE(SyncP6)
begin
INSERT INTO [dbo].[material_audit]
([ID_SAP_Project],[ID_SAP_Material],[Order_Date],[Delivery_date],[Expected_Delivery_Date]
,[SignedBy],[Need_Date][material_Location],[Operation])
SELECT [ID_SAP_Project],[ID_SAP_Material],[Order_Date],[Delivery_date],[Expected_Delivery_Date]
,[SignedBy],[Need_Date],[material_Location],'UI'
FROM inserted;
END;
GO
更新查询
DECLARE @t_updates table ([Row] int IDENTITY(1,1), [ID_SAP_Project] [nvarchar](15), [ID_SAP_Material] [int], [Order_Date] [date], [Delivery_date] [date], [material_Location] [nvarchar](max))
INSERT INTO @t_updates
Values ('1H341J123',520034,'2017-11-10','2017-12-14','WH2 - Area C')
UPDATE [material_current]
SET [Order_Date] = (SELECT [Order_Date] FROM @t_updates WHERE [Row] = 1), [Delivery_date] = (SELECT [Delivery_date] FROM @t_updates WHERE [Row] = 1),
[material_Location] = (SELECT [material_Location] FROM @t_updates WHERE [Row] = 1)
WHERE [ID_SAP_Project] = (SELECT [ID_SAP_Project] FROM @t_updates WHERE [Row] = 1) AND [ID_SAP_Material] = (SELECT [ID_SAP_Material] FROM @t_updates WHERE [Row] = 1)