chaitu chaitu
asked on
on before trigger is not working
our application is running on multiple nodes and having concurrency issues.we have written below trigger to handle the concurrency issues. before inserting into EMPJOBS whether any jobs that are running at the last 1 minute on this @EMP_TYPE,@EMP_ID, @STORE_ID parameters .if we get count that means already same record that are currently running on the EMPJOBS table.
after this trigger is enabled even below statement is executed but records are not showing up.
insert into EMPJOBS values(1,'ddd',1111',getda te());
after this trigger is enabled even below statement is executed but records are not showing up.
insert into EMPJOBS values(1,'ddd',1111',getda
GO
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE TRIGGER [dbo].[EMPJOBS_Trigger] ON XXX.DBO.EMPJOBS
INSTEAD OF INSERT
AS
BEGIN
DECLARE @JOB_TYPE nvarchar
DECLARE @EMP_ID int
DECLARE @STORE_ID int
DECLARE @START_DATE date
DECLARE @COUNT int
SET @COUNT = (SELECT count(*) FROM EMPJOBS WHERE
EMP_TYPE= @EMP_TYPE and
EMP_ID=@EMP_ID and
STORE_ID=@STORE_ID and
START_DATE >= DATEADD(mi, -1, GETDATE()))
IF @COUNT > 0
BEGIN
PRINT 'JOB ALREADY RUNNING'
RAISERROR ('JOB ALREADY RUNNING', 16, 1)
--ROLLBACK TRANSACTION
RETURN
END
ELSE
PRINT 'CREATE JOB'
END
GO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DECLARE @JOB_TYPE nvarchar
DECLARE @EMP_ID int
DECLARE @STORE_ID int
DECLARE @START_DATE date
DECLARE @COUNT int