本文介绍了印象数增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击页面时,应仅在数据库中增加页面印象.
如何编写存储过程请问有谁可以帮我
前任.如果我单击页面,则单次展示应为1.
如果我单击页面第二次展示次数应为2.
如果我单击页面,则第三次印象计数应为3
When I Click the page impressions should be increased in database only.
How to write the stored procedure Can any one Help me
Ex. If I Click the page single time impressions should be 1.
If i Click page second time impressions count should be 2.
if i click page Third time impressions count shoudl be 3
推荐答案
CREATE TABLE Impressions
(page_id int, impression int )
对于存储过程-
For stored Procedures -
CREATE PROC [dbo].[IncresingCount]
(
@pageId int
)
AS
BEGIN
Declare @Counter int
Select @Counter= COUNT(impression) from Impressions where page_id=@pageId
IF @Counter=0
BEGIN
INSERT INTO Impressions(page_id, impression )
VALUES(@pageId,1)
END
ELSE
BEGIN
-- page_id exist, update the impression with 1 increament.
UPDATE Impressions
SET impression= (Select impression+1 from Impressions Where page_id=@pageId )
Where page_id=@pageId
END
END
--Select * from Impressions
执行存储过程
Execute the stored Procedures
EXEC [dbo].[IncresingCount] 1
全选并查看
Select all and see
Select * from Impressions
这篇关于印象数增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!