我有一个触发器,它从原始表格中获取旧值并将这些值放在另一个表格的一个单元格中,日期和用户除外,当发生任何更新时,原始表格的属性在插入原始表格时为空,例如(更新日期和 updateuser),所以当这个 raw 被更新时,这两个属性将被更新为当前日期和进行更新的用户,所以当它们为空时触发器应该获取这两个参数应该获取插入的值并且当它们不为空时应该得到新的值,但是触发器的语法是正确的,但结果是不正确的
ALTER Trigger [dbo].[OrdersUpdate] on [dbo].[Orders]
After Update
as
Declare @UpdateDate datetime, @UpdateUser uniqueidentifier
Set @UpdateDate=(Select UpdateDate from deleted)
Set @UpdateUser=(Select UpdateUser from deleted)
If @UpdateDate is null
Begin
Set @UpdateDate=(select UpdateDate from inserted)
End
Else
Set @UpdateDate=(select UpdateDate from deleted)
If @UpdateUser is null
Begin
Set @UpdateUser=(select UpdateUser from inserted)
End
Else
Set @UpdateUser=(select UpdateUser from deleted)
Insert Into UpdateRows
Select 'Orders', id,@UpdateDate,@UpdateUser,
convert(nvarchar,InvoiceID,1)+'_'+
convert(nvarchar,OrderID,1)+'_'+
MatterName+'_'+
convert(nvarchar,PrintID,1)+'_'+
OrderName+'_'+
CONVERT(nvarchar,lenght,1)+'_'+
CONVERT(nvarchar,Wide,1)+'_'+
CONVERT(nvarchar,Quantity,1)+'_'+
CONVERT(nvarchar,EnterDate,101)+'_'+
CONVERT(nvarchar,EndDate,101)
From deleted