SQL Server trigger to Prevent Duplicate Entries from my TimeLog Table -
i have timelog
table took entries of employees in , out
but due magnetic card reader machine take multiple entries of duplicate data
the difference in entries few seconds (which might goes different minutes)
unique identifiers:
- uid = user id
- type = in / out
- serial = card reader number
- checktime = time difference need check till 1 minute before
my trigger:
create trigger [dbo].[data_checkout] on [dbo].[tblname] after insert if exists (select * [dbo].[tblname] t inner join inserted on datepart(day, t.checktime) = datepart(day,i.checktime) , datepart(month, t.checktime) = datepart(month, i.checktime) , datepart(hour, t.checktime) = datepart(hour, i.checktime) , datepart(minute, t.checktime) = datepart(minute, i.checktime) , datepart(minute, t.checktime) = datepart(minute, dateadd(minute, -1, i.checktime)) , t.[uid] = i.[uid] , t.[type] = i.[type] , t.[serial] = i.[serial]) begin rollback raiserror ('duplicate data', 16, 1); end go
Comments
Post a Comment