为什么SSRS报告在开发中工作,而在生产中不工作

时间:2016-11-21 17:50:37

标签: tsql reporting-services parameters parameter-sniffing

我有一个SELECT语句(不是存储过程),我用它来在SSRS(Visual Studio 2010)中创建报告。

参数@ClassCode是导致故障的那个。但是在开发中它运行良好,但是当我将它部署到Production时它会永远渲染。

我假设它是一个参数嗅探器,我读到了如何在存储过程中修复它。但是我没有SP,我使用的是SELECT语句。

SELECT语句的解决方法是什么? 环境之间有什么区别?生产要强大得多。 我的查询如下:

;WITH cte1
AS
(
    SELECT  QuoteID,
             AccidentDate,
            PolicyNumber,
            SUM(PaidLosses) as PaidLosses
    FROM    tblLossesPlazaCommercialAuto
    WHERE   InsuredState IN  (@State)  AND AccidentDate BETWEEN @StartDate AND @EndDate AND TransactionDate <= @EndDate AND  Coverage = 'VehicleComprehensive'
    GROUP BY QuoteID,
            AccidentDate,
            PolicyNumber
),
cte3
AS
(
SELECT      
            cte1.Quoteid,
            cte1.PolicyNumber,
            cte1.AccidentDate,
            cc.TransactionEffectiveDate,
            cc.ClassCode,
                CASE
                WHEN ROW_NUMBER() OVER (PARTITION BY cte1.QuoteID, cte1.PolicyNumber,cc.AccidentDate ORDER BY (SELECT 0))=1 THEN cte1.PaidLosses 
                ELSE 0
            END  as PaidLosses--,
FROM        cte1 inner join tblClassCodesPlazaCommercial cc 
                        on cte1.PolicyNumber=cc.PolicyNumber 
                        AND cte1.AccidentDate=cc.AccidentDate
            AND cc.AccidentDate IS NOT NULL
    /* This is the one that gives me problem */
            WHERE  cc.ClassCode   IN (@ClassCode)
) 
SELECT  SUM(PaidLosses) as PaidLosses, c.YearNum, c.MonthNum
FROM    cte3 RIGHT JOIN tblCalendar  c ON c.YearNum = YEAR(cte3.AccidentDate) AND c.MonthNum = MONTH(cte3.AccidentDate)
WHERE   c.YearNum <>2017
GROUP BY  c.YearNum, c.MonthNum
ORDER BY  c.YearNum, c.MonthNum

1 个答案:

答案 0 :(得分:0)

使用Tuning Advisor查看工作负载需要哪些索引和统计信息。创建后 - 一切正常。