Microsoft Query:无法绑定多部分标识符

时间:2012-05-21 16:59:20

标签: sql

我正在尝试在Microsoft Query中编写一个查询,看起来因为别名存在一些问题,但我无法弄清楚如何修复它,任何帮助都将受到高度赞赏!

SELECT   item."No_",
         item.Description,
         ItemLedgerEntry."Location Code",
         Sum(ItemLedgerEntry."Remaining Quantity") As Stock,
         Sum(bo."Outstanding Quantity") As BackOrder
FROM Nav50.dbo.item item, Nav50.dbo.ItemLedgerEntry ItemLedgerEntry
LEFT OUTER JOIN (   SELECT SalesLine.No_,
                    Customer.Name, SalesLine."Location Code",
                    SalesLine."Outstanding Quantity"
                    FROM Nav50.dbo.Customer Customer, Nav50.dbo.SalesLine SalesLine
                    WHERE SalesLine."Sell-to Customer No_" = Customer.No_) bo
ON ((item."No_" = bo.No_) AND (ItemLedgerEntry."Location Code" = bo."Location Code"))
WHERE item.No_ = ItemLedgerEntry."Item No_" AND ((ItemLedgerEntry."Location Code"='STHLM') AND (ItemLedgerEntry."Remaining Quantity"<>$0))
GROUP BY item."No_", item.Description, ItemLedgerEntry."Location Code"

我得到的信息是:

  

无法绑定多部分标识符“item.No_”。

1 个答案:

答案 0 :(得分:1)

而不是使用双引号尝试使用方括号:

SELECT   item.[No_]

使用JOIN语法而不是表之间的逗号更新的完整查询。

SELECT   item.[No_],
         item.Description,
         ItemLedgerEntry.[Location Code],
         Sum(ItemLedgerEntry.[Remaining Quantity]) As Stock,
         Sum(bo.[Outstanding Quantity]) As BackOrder
FROM Nav50.dbo.item item
LEFT JOIN Nav50.dbo.ItemLedgerEntry ItemLedgerEntry
    ON item.[No_] = ItemLedgerEntry.[Item No_] 
LEFT OUTER JOIN 
(   
    SELECT SalesLine.[No_],
           Customer.Name, 
           SalesLine.[Location Code],
           SalesLine.[Outstanding Quantity]
    FROM Nav50.dbo.Customer Customer
    LEFT JOIN Nav50.dbo.SalesLine SalesLine
        ON SalesLine.[Sell-to Customer No_] = Customer.[No_]
) bo
    ON ((item.[No_] = bo.[No_]) 
        AND (ItemLedgerEntry.[Location Code] = bo.[Location Code]))
WHERE ((ItemLedgerEntry.[Location Code]='STHLM') 
    AND (ItemLedgerEntry.[Remaining Quantity]<>$0))
GROUP BY item.[No_], item.Description, ItemLedgerEntry.[Location Code]