本文介绍了我们如何在SQL Server 2012中的触发器中使用会话值并插入表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
How can we use session value in trigger in SQL Server 2012 and insert into a table? I created a session but getting confuse, how can i use session value into a trigger. I'm creating a log table for view all logs that which action is acted in main table. and please tell me how can I update table with update Trigger with new session value and ID fetch from main table to update data. In given code @ActionBy value I want from new session.
How can I do this? Please let me know about this.
我尝试过的事情:
What I have tried:
CREATE TRIGGER EpaperTrgrUpdate
ON EPaper
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @EpaperId INT
DECLARE @Date datetime
DECLARE @ActionBy nvarchar(50)
DECLARE @Action varchar(50)
SELECT @EpaperId = EPaper.SrNo, @Date = date, @ActionBy = EPaper.ActionBy
FROM EPaper
IF UPDATE(IMG)
BEGIN
SET @Action = 'Image Updated'
END
IF UPDATE(Date)
BEGIN
SET @Action = 'Date Updated'
END
INSERT INTO Epaper_Log
VALUES(@EpaperId, @Date, @Action, @ActionBy)
END
推荐答案
这篇关于我们如何在SQL Server 2012中的触发器中使用会话值并插入表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!