Link to home
Start Free TrialLog in
Avatar of tom_optimum
tom_optimumFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Query - List most used report

Hi all,

I have a table structure like this:

ReportLogID, UserID, ReportID, ReportName, Viewed

The table stores which users have run which reports in our system.

I would like to run a SQL query that lists the reports (grouped by ReportID) and shows me and the number of times it has been run.

I would also like to choose the start and end date that I want to run the query for (this is the Viewed field).

I can do this in Crystal Reports (where I am comfortable!), but I am not sure what to do in SQL.

Any hep would be great.

Thanks,

Tom
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

The below query will let you know that which report run how many times.

SELECT
	t2.Name AS ReportName, ReportID,InstanceName,COUNT(1) counts
	FROM dbo.ExecutionLog t1
    JOIN dbo.Catalog t2
    ON t1.ReportID = t2.ItemID
	GROUP BY t2.Name , ReportID,InstanceName

Open in new window

Avatar of tom_optimum

ASKER

Great - thanks.

So, I am using this:

SELECT ReportID, ReportName, count(*), min(Viewed), max(Viewed)
FROM tblReportViewLog
GROUP BY ReportID, ReportName

Open in new window

What would I need to do so I can type in the start and end date instead of min and max?

Thanks,

Tom
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great - thanks.

Here is what I used int he end
-- Reports run over all time
SELECT ReportID, ReportName, count(*), min(Viewed), max(Viewed)
FROM tblReportViewLog
GROUP BY ReportID, ReportName

-- Reports run between two dates
SELECT ReportID, ReportName, Count(ReportID) Counts FROM tblReportViewLog
WHERE Viewed BETWEEN '2013-09-01' AND '2014-07-29'
GROUP BY ReportID, ReportName

Open in new window

Thanks for you help.

Tom
Great help guys.

Thanks,

Tom