?
Solved

SQL Query - List most used report

Posted on 2014-07-29
6
Medium Priority
?
386 Views
Last Modified: 2014-07-29
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
0
Comment
Question by:tom_optimum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 40226380
the starter is easy:
 select ReportID, count(*), min(Viewed), max(Viewed)
from yourtable
group by ReportID

Open in new window

you may want more data/columns, in which case you want to read up this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_3203-DISTINCT-vs-GROUP-BY-and-why-does-it-not-work-for-my-query.html
0
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40226385
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

0
 

Author Comment

by:tom_optimum
ID: 40226388
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Assisted Solution

by:Vikas Garg
Vikas Garg earned 1000 total points
ID: 40226392
Hello,

try this for your local table

SELECT ReportName,Count(ReportID) Counts FROM YourTable
	WHERE Viewed BETWEEN DATE1 AND DATE2
	group by ReportName

Open in new window

0
 

Author Comment

by:tom_optimum
ID: 40226422
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
0
 

Author Closing Comment

by:tom_optimum
ID: 40226426
Great help guys.

Thanks,

Tom
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question