spStats_TopPages
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@BeginDate | datetime | IN | |
@EndDate | datetime | IN | |
@QueryType | int | IN |
Definition
Copy
CREATE PROCEDURE [dbo].[spStats_TopPages]
(
@BeginDate datetime,
@EndDate datetime,
@QueryType int
)
AS
BEGIN
set nocount on
DECLARE @InsertTable Table
(
PageName nvarchar(255),
Pageid int,
PageViews int,
PageVisits int
)
INSERT INTO @InsertTable
SELECT
sp.PageName,
sp.id,
sum(ps.PageViews) PageViews,
sum(ps.Visits) Visits
FROM [dbo].[StatisticsDayPage] ps
inner join SitePages sp on ps.PageID = sp.ID
WHERE ps.YYYYMMDD >= CONVERT(nchar(8),@BeginDate,112)
AND ps.YYYYMMDD <= CONVERT(nchar(8),@EndDate,112)
GROUP BY sp.ID, sp.PageName
DECLARE @SelectTable Table
(
PageName nvarchar(255),
Pageid int,
PageViews int,
PageVisits int
)
If @QueryType = 0
begin
INSERT INTO @SelectTable
SELECT TOP 10 * FROM @InsertTable ORDER BY PageViews DESC
end
If @QueryType = 1
begin
INSERT INTO @SelectTable
SELECT TOP 10 * FROM @InsertTable ORDER BY PageVisits DESC
end
If @QueryType = 2
begin
INSERT INTO @SelectTable
SELECT TOP 10 * FROM @InsertTable ORDER BY PageViews ASC
end
If @QueryType = 3
begin
INSERT INTO @SelectTable
SELECT TOP 10 * FROM @InsertTable ORDER BY PageVisits ASC
end
If @QueryType = 4
begin
INSERT INTO @SelectTable
SELECT * FROM @InsertTable ORDER BY PageViews DESC
end
SELECT * FROM @SelectTable
END