本文介紹了在sql server中創建視圖“每個視圖或函數中的名稱必須是唯一的"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試在 sql server 2012 中創建視圖,但出現此錯誤消息
I'm trying to create view in sql server 2012, but I have this error message
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
推薦答案
在您的情況下,表 dbo.vFileImportDPERDebtors 將有一個名為Lastname"的列.如果您按名稱選擇所有列(即,將 * 擴展為名稱),您可以為一個或兩個姓氏列設置別名,SELECT M.Lastname as Lastname1, Managers.Lastname as Lastname2...
.通常認為最好的做法是不使用SELECT *".
In your case the table dbo.vFileImportDPERDebtors will have a column called 'Lastname'. If you select all of your columns by name (i.e. expand * into names) you can alias one or both of the Lastname columns, SELECT M.Lastname as Lastname1, Managers.Lastname as Lastname2...
. It's generally considered best-practice not to use 'SELECT *'.
這篇關于在sql server中創建視圖“每個視圖或函數中的名稱必須是唯一的"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!