日期:2014-05-17 浏览次数:20443 次
create proc my_FilteringRecords @time int,@result int output
as
BEGIN
SET NOCOUNT ON;
select *,row_number() over (partition by sn order by arDate) re
into #cu3
from AttendanceRecord where states=0
select a.*
into #cu2
from #cu3 a
inner join #cu3 b on a.sn=b.sn and a.re-b.re=1
where datediff(second,b.arDate,a.arDate)/60>=@time
declare @err int
begin Tran
insert SaveRecord (id,SN,Name,arDate)
select id,SN,Name,arDate from #cu2
union all
select id,SN,Name,arDate from #cu3
where re=1 and sn in (select distinct sn from #cu2)
order by SN,arDate
set @err=@@error
if @err>0
goto label_end
update AttendanceRecord set states=1 where sn in (select distinct sn from #cu3)
set @err=@@error
label_end:
if @err>0
begin
set @result=0
rollback Tran
end
else
begin
set @result=1
commit Tran
end
end
go