当前位置:  开发笔记 > 编程语言 > 正文

无法绑定SQL Server 2012多部分标识符

如何解决《无法绑定SQLServer2012多部分标识符》经验,为你挑选了1个好方法。

我有4个桌子我正在参加Adventureworks 2012.我无法弄清楚为什么我得到'无法绑定错误'.

Msg 4104,Level 16,State 1,Line 7

无法绑定多部分标识符"Production.ProductCategory.Name".

消息4104,级别16,状态1,第1行

无法绑定多部分标识符"Production.ProductCategory.Name".

SELECT
    COUNT(WorkOrderID) AS TotalWorkOrders, 
    [Production].[ProductCategory].[Name]
FROM [Production].[WorkOrder] WO
INNER JOIN [Production].[Product] P ON WO.[ProductID] = P.[ProductID]
INNER JOIN [Production].[ProductSubcategory] PS ON PS.[ProductSubcategoryID] = P.[ProductSubcategoryID]
INNER JOIN [Production].[ProductCategory] PC ON PC.[ProductCategoryID] = PS.[ProductCategoryID]
WHERE WO.[StartDate] >= '1999—03-08' AND WO.[StartDate] <= '2008-05-02'
GROUP BY [Production].[ProductCategory].[Name]

Gordon Linof.. 5

您的查询已为表提供 [Production].[ProductCategory]了别名PC.您需要在查询的其余部分中使用它:

SELECT COUNT(WO.WorkOrderID) AS TotalWorkOrders, 
       PC.[Name]
FROM [Production].[WorkOrder] WO INNER JOIN
     [Production].[Product] P
     ON WO.[ProductID] = P.[ProductID] INNER JOIN
     [Production].[ProductSubcategory] PS 
     ON PS.[ProductSubcategoryID] = P.[ProductSubcategoryID] INNER JOIN
     [Production].[ProductCategory] PC
     ON PC.[ProductCategoryID] = PS.[ProductCategoryID]
WHERE WO.[StartDate] >= '1999—03-08' AND WO.[StartDate] <= '2008-05-02'
GROUP BY PC.[Name];

为表提供别名后,需要引用该别名而不是原始表名.



1> Gordon Linof..:

您的查询已为表提供 [Production].[ProductCategory]了别名PC.您需要在查询的其余部分中使用它:

SELECT COUNT(WO.WorkOrderID) AS TotalWorkOrders, 
       PC.[Name]
FROM [Production].[WorkOrder] WO INNER JOIN
     [Production].[Product] P
     ON WO.[ProductID] = P.[ProductID] INNER JOIN
     [Production].[ProductSubcategory] PS 
     ON PS.[ProductSubcategoryID] = P.[ProductSubcategoryID] INNER JOIN
     [Production].[ProductCategory] PC
     ON PC.[ProductCategoryID] = PS.[ProductCategoryID]
WHERE WO.[StartDate] >= '1999—03-08' AND WO.[StartDate] <= '2008-05-02'
GROUP BY PC.[Name];

为表提供别名后,需要引用该别名而不是原始表名.

推荐阅读
mobiledu2402851203
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有