我对SQL Server有些新意,并尝试在INTO
语句中使用while循环,但由于某种原因,SQL Server不允许我DECLARE
我的变量INTO
{1}}声明......似乎没有/ while循环,但是我需要能够DECLARE
并定义我的变量以在while循环中使用...任何想法?
--Calculations portion of query
SELECT
FNL.*
INTO
#Final_Calc
FROM
(
DECLARE @i INT
SET @i = 0
WHILE (@StartDte + @i <= @EndDte)
BEGIN
SET @i = @i + 1
SELECT
YEAR(ACD.WorkDte) AS WorkDte,
'LOB - ALL ACM' AS RptType,
'Month' AS RptLvl
FROM
#FinalResults ACD
WHERE
ACD.WorkDte BETWEEN @StartDte AND @StartDte + @i
GROUP BY
Year(ACD.WorkDte), ACD.LOB
END
GO) fnl
所以,它不喜欢DECLARE @i INT
部分......