尝试在sql server 2012中创建视图,但我有此错误消息
Column names in each view or function must be unique. Column name 'Lastname' in view or function 'vFileImportDPERManagers' is specified more than once.
这是我的观点代码:
GO
CREATE VIEW [dbo].[vFileImportDPERManagers]
AS
SELECT M.*,
Managers.*
FROM dbo.vFileImportDPERDebtors M WITH (NOLOCK)
CROSS APPLY
(
SELECT
M1.Man.value('@j11','varchar(20)') as ManagerKey,
M1.Man.value('@j12','varchar(50)') as Lastname,
M1.Man.value('@j13','varchar(50)') as Firstname,
M1.Man.value('@j14','numeric') as ManagerFunctionId
FROM DebtorXml.nodes('d1/d36/t324/j1') as M1(Man)
) as Managers
GO
答案 0 :(得分:0)
在您的情况下,表dbo.vFileImportDPERDebtors将有一个名为' Lastname'的列。如果您按名称选择所有列(即将*展开为名称),则可以为一个或两个Lastname列SELECT M.Lastname as Lastname1, Managers.Lastname as Lastname2...
添加别名。通常认为不使用“SELECT *'。