从以下脚本获取错误

时间:2016-02-06 09:52:26

标签: sql-server sql-server-2008 stored-procedures compiler-errors

我将为每个表记录创建SI,从存储过程中获取错误:

  

没有为'cte_Alldates'的第6列指定列名。

请检查此脚本并告诉我问题所在:

table screenshot

和存储过程:

print

1 个答案:

答案 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
)