一个存储过程代码

来源:互联网 发布:高中数学矩阵的用途 编辑:程序博客网 时间:2024/05/17 05:57

一个ip24小时内有10条留言,

一个ip,对一个项目在24小时内只能参与一次

/*
检测一个ip再24内是不是有10条留言
一个ip,一个项目24小时内只能参与一次
*/
CREATE PROCEDURE get_lunpan
(
 @item_id int,
 @ipaddress  varchar(100),
 @back int out
)
AS
declare @countall int
select @countall = count(a.id)  from Cn_ActiveGame a  left outer join cn_adly b on a.adly_id=b.adly_id  where  b.item_id=@item_id  and b.lyip=@ipaddress  and a.addtime between DATEADD(hour,-24,getDate()) and getDate()
if (@countall > 9 )
 begin
  declare @Datatime1 datetime
                             if exists (select * from Cn_ActiveGame1  where ipaddress=@ipaddress and item_id=@item_id )
   begin
    select  @Datatime1 = max(addtime) from  Cn_ActiveGame1 where   ipaddress=@ipaddress
    if(DATEDIFF(hour,@Datatime1,getDate())>24)
                            begin
      set @back=1
      insert into Cn_ActiveGame1 (ipaddress,addtime,item_id) values (@ipaddress , getDate(),@item_id)
     end
    else                            
       set @back=0
    end
  else
   begin
    set @back=1  
                                           insert into Cn_ActiveGame1 (ipaddress,addtime,item_id) values (@ipaddress , getDate(),@item_id)
   end
 end
else
 begin
    set @back=0 
 end
GO

原创粉丝点击