nhmedia
asked on
How run report queries for a range of dates, not just a single date
Hi
I have a query that I run to get several key performance indicators for our website.
The query performs calculations for a single date and shows the results as a single-row table. How could I extend my query so that it runs from a start date to an end date and creates a row for each date in the range?
KR
I have a query that I run to get several key performance indicators for our website.
The query performs calculations for a single date and shows the results as a single-row table. How could I extend my query so that it runs from a start date to an end date and creates a row for each date in the range?
KR
DECLARE
@date as date
set @date = '9/29/2011'
-- Individual urls
--SELECT URL,COUNT(URL) AS [views] FROM [DataBase2].[dbo].[tblPageViews] (nolock) where SiteID = '31'
-- and UserAgent not like '%bot%'
--and username <> 'Guest'
-- and (URL like '%test%' or url like '%btw%')
-- and date = @date
-- GROUP BY URL order by [views] desc
Select @date as date,
(SELECT count( 'hits') as ContentViews
FROM [DataBase2].[dbo].[tblPageViews] (nolock) as MobileSite where
siteid = '31'
and UserAgent not like '%bot%'
and username <> 'Guest'
and (URL like '%news%' or url like '%rc/%' or url like '%blog/%' )
and date = @date ) as MemberContent,
(SELECT count( 'hits') as testViews
FROM [DataBase2].[dbo].[tblPageViews] (nolock) as MobileSite where
siteid = '31'
and UserAgent not like '%bot%'
and username <> 'Guest'
and (URL like '%test%' or url like '%btw%')
and date = @date ) as Membertest,
(SELECT count( 'hits') as ContentViews
FROM [DataBase2].[dbo].[tblPageViews] (nolock) as MobileSite where
siteid = '31'
and UserAgent not like '%bot%'
and username = 'Guest'
and (URL like '%news%' or url like '%rc/%' or url like '%blog/%' )
and date = @date ) as GuestContent,
(SELECT count( 'hits') as testViews
FROM [DataBase2].[dbo].[tblPageViews] (nolock) as MobileSite where
siteid = '31'
and UserAgent not like '%bot%'
and username = 'Guest'
and (URL like '%test%' or url like '%btw%' )
and date = @date ) as Guesttest,
(SELECT count( 'hits') as ContentViews
FROM [DataBase2].[dbo].[tblPageViews] (nolock) as MobileSite where
siteid = '32'
and UserAgent not like '%bot%'
and username<>'Guest'
--and (URL like '%news%' or url like '%rc/%' or url like '%blog/%' )
and date = @date ) as smMember,
(SELECT count( 'hits') as testViews
FROM [DataBase2].[dbo].[tblPageViews] (nolock) as MobileSite where
siteid = '32'
and UserAgent not like '%bot%'
and username = 'Guest'
--and (URL like '%test%' or url like '%btw%' )
and date = @date ) as smGuest
--Select username, COUNT(username) AS views FROM [DataBase2].[dbo].[tblPageViews] (nolock)where
--SiteID = '" & ddChooseSite.SelectedValue & "' " _
-- & "and UserAgent not like '%bot%' and username <> 'Guest' " & DateParamater & " " & txtFreeRangeSQL.Text & " " _
-- & " GROUP BY username order by views desc"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER