if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_PageViews_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[cs_PageViews_Add]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE    Proc [dbo].cs_PageViews_Add
(
	@URL nvarchar(512),
	@VisitCount int
)
AS

DECLARE @DTStamp AS DateTime
SET @DTStamp = GetDate()

IF EXISTS (SELECT URL FROM cs_PageViews WHERE URL = @URL AND DATEDIFF(HOUR, DateTimeStamp, @DTStamp) < 1)
	UPDATE cs_PageViews
	SET cs_PageViews.VisitCount = cs_PageViews.VisitCount + @VisitCount
        WHERE URL = @URL
ELSE
	INSERT INTO cs_PageViews
		(URL, VisitCount, DateTimeStamp)
	VALUES
		(@URL, @VisitCount, @DTStamp)




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

grant execute on [dbo].[cs_PageViews_Add] to public
go
