如何将COALESCE语句添加到现有视图

时间:2015-09-24 17:14:05

标签: sql sql-server alter sql-view

这是我正在研究的观点。它工作正常, 但我打算在评论中添加COALESCE声明 这个脚本的一部分。谁会知道如何写 脚本正确。当我合并它们时,出现了错误。

CREATE VIEW [dbo].[VW_Bzo_D]
AS WITH today AS
    (SELECT *
    FROM [dbo].[Bz_DAYS]
    WHERE [DATE] = CAST(GETDATE() AS DATE)
    ),
pd AS  (SELECT [DATE] AS REPORTING_PERIOD
        FROM dbo.Bz_DAYS
        WHERE DAY([DATE]) = 1
        )
SELECT  sp.*,
        rp.REPORTING_PERIOD,
        ac.DATE_ORDINAL AS CUSTOMER_ACCEPTANCE_ORDINAL,
        mv.DATE_ORDINAL AS CUSTOMER_MOVE_ORDINAL,
        today.DATE_ORDINAL TODAY_ORDINAL
/*sp.[CUSTOMER_MOVE], sp.[CUSTOMER_REQUESTED], sp.[LEASE_SIGNED_BY_GSA],
    sp.[SUBMITTED_TO_GSA], sp.[CUSTOMER_ACCEPTANCE],

COALESCE(sp.[CUSTOMER_MOVE], sp.[CUSTOMER_REQUESTED],       sp.[LEASE_SIGNED_BY_GSA],
    sp.[SUBMITTED_TO_GSA], sp.[CUSTOMER_ACCEPTANCE]
    ) AS REPORT_MONTH
*/
FROM dbo.Bzo_Den sp

错误是:

  

每个视图或函数中的列名必须是唯一的。列名   视图或函数'VW_Bzo_D'中的'CUSTOMER_MOVE'被指定为多于   一次。

1 个答案:

答案 0 :(得分:0)

我不知道这是否会有所帮助,但您是否尝试使列名称混淆,这会给您带来麻烦?

其他一位用户遇到了类似的问题,他尝试了别名。请看下面的链接

http://www.mathworks.com/matlabcentral/fileexchange/20836-csv2cell

希望它有所帮助。