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 also know how can I get ID in where condition while I update data using update trigger ?
Plz let me know about all this...
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
Here ActionBy data I want get from session. in normal table I can insert or update session value, but i'm getting how can I get session value in trigger.