2016-07-15 84 views
0

構建物中不支持我有,我想創建在SSRS數據集的查詢,但我得到一個錯誤的說法,OVER SQL在SSRS

The OVER SQL construct or statement is not supported.

我使用的查詢是如下:

SELECT AM, REP, PRIM_SPEC, SUM(TOT_CALL) 
FROM (
     SELECT AM, REP, SUM(TOT_CALL) as TOT_CALL, 
     CASE 
      WHEN ROW_NUMBER() OVER (PARTITION BY REP ORDER BY SUM(TOT_CALL) DESC) > 5 
      THEN 'Other' 
      ELSE prim_spec 
     END AS prim_spec 
     FROM DEMO_CALL 
     WHERE PERIOD >= @Mese 
     AND (REP IN (@REP)) 
     AND (AM = @AM) 
     GROUP BY AM, REP, prim_spec 
) A 
GROUP BY AM, REP, PRIM_SPEC 
ORDER BY 1,2,4 DESC 

我該如何使用OVER SQL Construct來解決這個問題?

+0

你使用哪種連接類型連接到SQL Server? – Mike

回答

1

這不是SSRS的問題,而是SQL語句本身。在生成之前,您無法比較您的ROW_NUMBER。試試這個:

SELECT distinct AM, REP, TOT_CALL, 
CASE 
    WHEN RN > 5 
    THEN 'Other' 
    ELSE prim_spec 
    END AS prim_spec 
FROM (
SELECT AM, REP, SUM(TOT_CALL) as TOT_CALL, ROW_NUMBER() OVER (PARTITION BY REP ORDER BY SUM(TOT_CALL) DESC) as RN 
FROM DEMO_CALL 
WHERE PERIOD >= @Mese 
    AND (REP IN (@REP)) 
    AND (AM = @AM) 
GROUP BY AM, REP 
) DEMO_CALL 
GROUP BY AM, REP, prim_spec 
ORDER BY 1,2,4 DESC 
+0

謝謝史蒂芬,實際上,我已經使用的查詢,即使拋出了不支持的錯誤後,給出了結果集。不過,我也嘗試了你的查詢,結果證明它會提升性能.... –