如何在SQL和SSRS报告中增加年数?

时间:2016-11-30 20:53:31

标签: reporting-services

我有一个预测算法

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年等 感谢。

1 个答案:

答案 0 :(得分:1)

您的案例陈述中的其他内容将始终包含Null。试试这个。

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