Solved

SQL Query - List most used report

Posted on 2014-07-29
6
375 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 250 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 15

Assisted Solution

by:Vikas Garg
Vikas Garg earned 250 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

756 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