2016-11-30 1 views
0

私はSQLとSSRSレポートの年数を増やすにはどうすればよいですか?

WITH CTE_AllIDs AS 
(
SELECT TOP 22 ID = ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) 
FROM sys.columns 
) 
SELECT 
    c.ID 
,OrderMonth = CASE WHEN r.ID IS NOT NULL 
     THEN r.OrderMonth 
     -- elaborate function to get the short month name and year 
     ELSE ordermonth + 1 
     END 
,OrderQuantity 
,Trend 
,Forecast = CASE WHEN Trend IS NOT NULL AND c.ID <> (SELECT MAX(ID) FROM #Temp_Regression) 
     THEN NULL 
     -- For the last actual value (September in this example), we want forecast to have the same 
     -- value as the trendline (instead of NULL). This prevents a gap in the line charts in SSRS. 
     WHEN Trend IS NOT NULL AND c.ID = (SELECT MAX(ID) FROM #Temp_Regression) 
     THEN Trend 
     -- If trend is not found, it means we can calculate a forecast. 
     -- However, we also need to check if the month for which we calculate the forecast comes after 
     -- the actual values. Suppose we don't have values for January, then we don't want to calculate 
     -- a forecast for January as well. Only for the last 3 months of the year in this example. 
     WHEN Trend IS NULL AND c.ID > (SELECT MAX(ID) FROM #Temp_Regression) 
     THEN (@slope * (c.ID % 100)) + @intercept 



     ELSE NULL 
     END 
FROM CTE_AllIDs c 
LEFT JOIN #Temp_Regression r ON c.ID = r.ID; 

The results

がどのように私はOrderMoth列の値でこれを行うことができ、予測アルゴリズムは1ずつ増加がありますか? 2023、2024など ありがとうございました。

答えて

0

あなたのケースステートメントのあなたのElseには常にNullが含まれます。これを試して。

+0

ありがとうWEI_DBA! – Ztrew

関連する問題