日期:2014-05-18  浏览次数:20416 次

60分修改一个简单的统计存储过程
这是以前的一个,点击一次加1
CREATE   PROCEDURE   addcount
@ID   int
AS
Update   news
Set   hits   =   hits   +   1
Where   ID   =   @ID
GO
现在修改的要求如下:
点击一下,判断数据表中点击数是否大于20000,如果大于20000,就加1
否则就加上当前时间的秒数。
马上结贴,谢谢

------解决方案--------------------
CREATE PROCEDURE addcount
@ID int
AS
Update news
Set hits = hits + datepart(ss,getdate())
Where ID = @ID and hits> 20000
GO

------解决方案--------------------
CREATE PROCEDURE addcount
@ID int
AS
Update news
Set hits = hits + case when hits> 20000 then 1 else DATEPART(second,getdate()) end
Where ID = @ID
GO

------解决方案--------------------
CREATE PROCEDURE addcount
@ID int
AS
Update news
Set hits = hits + (case when hits> 20000 then 1 else datepart(ss,getdate()) end)
Where ID = @ID
GO
------解决方案--------------------
没看清楚....
------解决方案--------------------
支持楼上
------解决方案--------------------
Update news
Set hits = hits+case when hits> 20000 then 1 else datepart(second,getdate()) end
Where ID = @id

------解决方案--------------------
CREATE PROCEDURE addcount
@ID int
AS
Update news
Set hits = hits + case when hits> 20000 then 1 else datepart(second,getdate()end
Where ID = @ID