Link to home
Start Free TrialLog in
Avatar of wasabi3689
wasabi3689Flag for United States of America

asked on

how to output how many time each report run?

I have the following query
SELECT max([Name])
      --,[Path]
      --,[TimeStart]
      --,[TimeEnd]
      --,[UserName]
      --,[day#]
        --,Created_Date
      ,COUNT(Name)
  FROM [AnalysisReport].[dbo].[SSRSReportRunTime]
  GROUP BY NAME

I have to have the result - how many count each report run total with one time each time cpount although maybe a report may run more than once a day
Avatar of David Todd
David Todd
Flag of New Zealand image

Hi,

If grouping by name, why do you have max( name )?

Isn't the correct query
select
    name
    , count( * )
from tablename
group by
    name
;

Regards
  David
Avatar of Bill Prew
Bill Prew

What do you want the output 'report' to look like?


»bp
Avatar of wasabi3689

ASKER

each report may run by an user more than once in a day. If more than once, there will be two rows in a day. But I only want the latest run and count one only no matter how many entries in a day for a report run. That is why I put max function. So far my query listed captures all the run counts in a day. How to fix it?
Wouldn't you then want

SELECT [Name]
      ,MAX(Created_Date)
      ,COUNT(Name)
FROM [AnalysisReport].[dbo].[SSRSReportRunTime]
GROUP BY NAME

Open in new window

Since you stated you always want a COUNT of 1 for the latest date, then perhaps you are looking for:

SELECT Name, MAX(Created_Date) Date, 1 Count
FROM SSRSReportRunTime
GROUP BY NAME;

Open in new window


»bp
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.