Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

SSRS report execution much slower than SSMS

$
0
0

Hi,

When the below query is executed in SSMS it takes about 25 seconds to run:

DECLARE @FINANCIALYEAR VARCHAR(4)
DECLARE @FINPERIOD VARCHAR(4)

SET @FINANCIALYEAR = '2013'
SET @FINPERIOD = '10'

SELECT
	CASE 
		WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2 
			THEN YEAR(dbo.SALESTABLE.CREATEDDATE) - 1 
		WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4 
			THEN YEAR(dbo.SALESTABLE.CREATEDDATE) 
		WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) = 3 AND YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011 
			THEN YEAR(dbo.SALESTABLE.CREATEDDATE) 
		ELSE YEAR(dbo.SALESTABLE.CREATEDDATE) - 1
	END AS [Fin Year],
	CASE 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 10 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 3 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 2 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) = 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) = 3 
			THEN 13 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2013 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 3 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 9 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 3 
		END AS [Period],
		dbo.SALESTABLE.SALESID AS [Sales ID],
		CONVERT(DECIMAL(12, 2), SUM(dbo.SALESLINE.LINEAMOUNT)) AS [Value],
                                dbo.SALESTABLE.SALESNAME AS [Name]
FROM dbo.SALESTABLE
INNER JOIN dbo.SALESLINE ON dbo.SALESTABLE.SALESID = dbo.SALESLINE.SALESID
WHERE (
	CASE 
		WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2 
			THEN YEAR(dbo.SALESTABLE.CREATEDDATE) - 1 
		WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4 
			THEN YEAR(dbo.SALESTABLE.CREATEDDATE) 
		WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) = 3 AND YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011 
			THEN YEAR(dbo.SALESTABLE.CREATEDDATE) 
		ELSE YEAR(dbo.SALESTABLE.CREATEDDATE) - 1 END) IN (@FINANCIALYEAR)
	AND 
		(CASE 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 10 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 3 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 2 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) = 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) = 3 
			THEN 13 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2013 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 3 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 9 
		WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4 
			THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 3 
		END) IN (@FINPERIOD)
	AND GBORDER = '1'
	AND SALESTABLE.SALESTYPE = '3'
GROUP BY MONTH(dbo.SALESTABLE.CREATEDDATE), YEAR(dbo.SALESTABLE.CREATEDDATE), dbo.SALESTABLE.SALESID, dbo.SALESTABLE.SALESNAME
ORDER BY 1, 2 ASC

When the same query is executed as part of an SSRS report it takes over 10 minutes. In the SSRS report it is run when a particular financial period is selected on a different report page. It gets its parameters from that selection.Is there any way of finding out why it takes so long in SSRS?

Cheers

Paul


Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>