在sql server中创建视图“每个视图或函数中的名称必须是唯一的"

Create view in sql server quot;names in each view or function must be uniquequot;(在sql server中创建视图“每个视图或函数中的名称必须是唯一的)
本文介绍了在sql server中创建视图“每个视图或函数中的名称必须是唯一的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试在 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中创建视图“每个视图或函数中的名称必须是唯一的"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Sending parameters to stored procedures vb.net(将参数发送到存储过程 vb.net)
Insert multiple rows, count based on another table columns(插入多行,根据另一个表列计数)
How to hold the location of an image in a SQL Server database?(如何在 SQL Server 数据库中保存图像的位置?)
How to send to email (outlook) the selected items in SQL Server database using vb.net(如何使用 vb.net 将 SQL Server 数据库中的选定项目发送到电子邮件(Outlook))
datagrid checkbox writes Null instead of 0 (false) into database(datagrid 复选框将 Null 而不是 0 (false) 写入数据库)
DBCC CheckDb-any ways to detect errors vb.net?(DBCC CheckDb-vb.net 有什么检测错误的方法吗?)