SQL 错误:无法绑定多部分标识符
Posted
技术标签:
【中文标题】SQL 错误:无法绑定多部分标识符【英文标题】:SQL error: The multi-part identifier could not be bound 【发布时间】:2014-03-24 07:45:08 【问题描述】:我有一个 sql 查询:
select contactID, items.name, orders.confirmed, deleted, dbo.polish_date(orders.crDATE), orders.orderID, IDtowar, IDspecial, IDstatus, IDtype, description
from orders, items
LEFT JOIN contacts ON orders.orderID = IDorder
where (orders.IDuser='38824' and orders.IDtowar=items.itemID)
order by orders.crDATE
而且我每次都有这个错误:
无法绑定多部分标识符“orders.orderID”。
【问题讨论】:
orderID
列是否存在于orders
表中?
【参考方案1】:
试试这个
SELECT contactID, items.name, orders.confirmed, deleted, dbo.polish_date(orders.crDATE), orders.orderID, IDtowar, IDspecial, IDstatus, IDtype, description
FROM orders
LEFT JOIN contacts ON orders.orderID = IDorder
LEFT JOIN items ON orders.IDtowar = items.itemID
WHERE orders.IDuser='38824'
ORDER By orders.crDATE
【讨论】:
【参考方案2】:您需要在两个表中的匹配字段上将订单连接到项目,并在其匹配字段上类似地将联系人连接到订单(假设这是链接所在的位置)。
SELECT contactID, items.name, orders.confirmed, deleted,
dbo.polish_date(orders.crDATE), orders.orderID,
IDtowar, IDspecial, IDstatus, IDtype, description
FROM orders
LEFT JOIN items ON items.orderID = orders.orderId
LEFT JOIN contacts ON contacts.ContactId = orders.ContactId
WHERE (orders.IDuser='38824' and orders.IDtowar=items.itemID)
ORDER BY orders.crDATE
【讨论】:
【参考方案3】:我会告诉你是什么帮助了我,我认为它也适用于你的。我从 From 子句中删除了我要加入的表 - 就像一个魅力。这就是我认为你的样子:
SELECT contactID, items.name, orders.confirmed, deleted, dbo.polish_date(orders.crDATE), orders.orderID, IDtowar, IDspecial, IDstatus, IDtype, description
FROM items -- Delete orders from clause
LEFT JOIN contacts ON orders.orderID = IDorder
WHERE (orders.IDuser='38824' and orders.IDtowar=items.itemID)
ORDER BY orders.crDATE
【讨论】:
以上是关于SQL 错误:无法绑定多部分标识符的主要内容,如果未能解决你的问题,请参考以下文章