我正在尝试更改视图 - 我只是想提供运行的SELECT
语句的完整新定义。
我的SQL语句看起来像这样(我出于隐私原因改变了一些cols):
ALTER VIEW dbo.vwViewNameHere
AS
SELECT
h.BATCH, h.batch_name COLLATE Latin1_General_CI_AS,
h.serial_from, h.serial_to, h.batch_description
FROM
(SELECT
BATCH, LTRIM(RTRIM(NAME)) COLLATE Latin1_General_CI_AS AS batch_name,
aa AS serial_from, bb AS serial_to,
CONVERT(varchar(99), BATCH) + ' - ' + LTRIM(RTRIM(NAME)) COLLATE Latin1_General_CI_AS AS batch_description
FROM
[IPAddress].database.dbo.tablename) AS h
FULL OUTER JOIN
dbo.othertablename AS b WITH (nolock) ON LTRIM(RTRIM(b.Batch_Name)) = h.batch_name COLLATE Latin1_General_CI_AS
AND h.serial_from = b.Start_Serial
AND h.serial_to = b.End_Serial
WHERE
(b.Batch_ID IS NULL)
我已经确认select正确运行但是当我运行alter view语句时,我收到一条消息:
消息4511,级别16,状态1,过程vwViewNameHere_NotImportedyet,第3行
创建视图或函数失败,因为没有为第2列指定列名。
我运行了CREATE VIEW
语句,以便先前备份此视图定义,并且创建时没有错误。
答案 0 :(得分:2)
您没有为第2列指定名称,正如消息所说的那样。指定名称:
h.batch_name COLLATE Latin1_General_CI_AS as batch_name
答案 1 :(得分:1)
从错误信息判断:
消息4511,级别16,状态1,过程vwViewNameHere_NotImportedyet,第3行 创建视图或函数失败,因为没有为第2列指定列名。
你可以尝试一下:
ALTER VIEW dbo.vwViewNameHere
AS
SELECT
h.BATCH, h.batch_name COLLATE Latin1_General_CI_AS as batch_name,
-- etc