2016-11-30 2 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 увеличивается на единицу в? 2023, 2024 и т. Д. Спасибо.

ответ

0

Ваше другое дело в вашем заявлении по делу всегда будет содержать Null. Попробуй это.

ELSE (Select Max(OrderMonth) From #Temp_Regression) + ((C.ID) - (Select Max(ID) From #Temp_Regression)) 
+0

Спасибо WEI_DBA! – Ztrew