set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGO-- =============================================-- Author:<Author,,shunzi>-- Create date: <Create 2007-04-03,,>-- Description:增加相片的票数-- =============================================alter TRIGGER [dbo].[sh_trigger_Phote_Vote] ON [dbo].[JiPhoto] for InsertAS declare @dattoday datetimedeclare @maxVote intset @dattoday=getdate()set @MaxVote=15declare @userid intdeclare @Cuid intBEGIN --求出插入的那条资料 Select @userid=Jiuid,@Cuid=Cuid from inserted set @userid=@userid Set @cuid=@cuid
--判断用户是不是在小天使列表中 if exists (Select * from sh_angel_list where Userid=@Cuid) Begin --判断用户是否已经有计过票数 if not exists (Select * from sh_Vote_Detailed where typevote='photo' and userid=@Cuid and convert(varchar(8),addtime,120)=convert(varchar(8),@dattoday,120)) Begin --增加投票日志
insert into sh_Vote_Detailed(typeVote,[vote],userid,cuid) values ('photo',3,@Cuid,@userid) --小天使开始计票 update sh_Angel_list set PhotoVote=PhotoVote+3 ,TotalVote=TotalVote+3 where userid=@Cuid End else Begin Select @MaxVote=sum(vote) from sh_Vote_Detailed where typevote='photo' and userid=@Cuid and convert(varchar(8),addtime,120)=convert(varchar(8),@dattoday,120) if @MaxVote<15 Begin --增加投票日志
insert into sh_Vote_Detailed(typeVote,[vote],userid,cuid) values ('photo',3,@Cuid,@userid) --小天使开始计票 update sh_Angel_list set PhotoVote=PhotoVote+3 ,TotalVote=TotalVote+3 where userid=@Cuid end end EndEND