答案 0 :(得分:1)
CTE需要为所有列指定列名。在这种情况下,您缺少第六列的列名称。您的cte_Alldates
CTE应为:
cte_Alldates AS
(
SELECT
name, Pamount, Rateofint, cdate, monthEnd, [day]=@today
FROM
cte_dates
UNION
SELECT
name, Pamount, Rateofint,
DATEADD(month, number, monthEnd),
CASE
WHEN DATEADD(month, number + 1, monthEnd) < @today
THEN DATEADD(month, number + 1, monthEnd)
ELSE @today
END,
[day]=@today
FROM
cte_dates c
CROSS JOIN
(SELECT number
FROM master..spt_values
WHERE type = 'p' AND number BETWEEN 0 AND 11) a
WHERE
dateadd(month, number, monthEnd) < @today
)