读书人

60分修改一个简单的统计存储过程解决办

发布时间: 2012-01-29 21:39:32 作者: rapoo

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

读书人网 >SQL Server

热点推荐