我已经写了一个更新触发器,当我更新只有一行,但更新多行时发生错误时工作正常。如何为多行更新写入触发器?
错误:
Msg 512, Level 16, State 1, Procedure Sale_OnUpdate, Line 14 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
这里是触发
ALTER TRIGGER [dbo].[Sale_OnUpdate] ON [dbo].[Sale]
AFTER Update
AS
Declare @ID as decimal
Declare @User as varchar(250)
Declare @Status as varchar(250)
set @ID = (Select ID from Inserted)
set @User = (Select UpdatedByUser from Inserted)
set @Status = Isnull((Select Status from Inserted),'')
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO [dbo].[Log]
(
[RecordID]
,[Date]
,[Time]
,[UserName]
,[TableName]
,[Action]
)
VALUES
(
@ID
,GetDate()
,GetDate()
,@User
,'Sale'
,'Update,' + @Status
)
END
我应该做的改变,使之成为多行工作。
但我想让这三个字段(ID,用户,状态)登录。 – 2012-02-29 05:10:16
@ MujassirNasir:那不是你的问题。 – 2012-02-29 05:11:03
我试过这个我知道它的作品,但我想写触发器来记录每一个动作。 – 2012-02-29 05:13:00