SSRS return TOP(n) rows

Although I cannot show the slow report that returned 4729 pages (shame ;)) I can use the generic ReportServer database for a demo.

It’s all about timing. First we need a parameter called param_rows that is an integer with a default value of -say- 100.

Next we need a dataset where param_rows is nested …

-- SlowestReports.sql

DECLARE @Rows INT = COALESCE(@param_rows, 100)

SELECT TOP(@Rows) ItemPath Report,
       TimeStart,
       TimeDataRetrieval
FROM [ReportServer].[dbo].[ExecutionLog3]
WHERE ItemPath <> ''
AND ItemAction = 'Render'
AND RequestType = 'Interactive'
AND Status = 'rsSuccess'
AND TimeStart BETWEEN @FromDate AND @ToDate + 1
ORDER BY TimeDataRetrieval DESC;

Then we can abuse the date range, with performance balanced by the number of rows returned (unlike “Filter” which returns all the rows but limits those displayed) …

Ok abuse doesn’t really work with ReportServer (that only holds 60 days by default) but you get the idea 🙂