无法绑定多部分标识符

时间:2015-01-19 10:52:51

标签: sql sql-server

此SQL查询有什么问题?

SELECT id AS Expr 
FROM EXTDATA.Monitoring.dbo.Exceptions 
WHERE EXTDATA.Monitoring.dbo.Exceptions.exceptionID = EXTDATA.Monitoring.dbo.RoomView.exceptionID

当我尝试执行查询时,收到此错误消息:

Msg  4104, Level  ##, State  1, Line 3
The multi-part identifier "EXTDATA.Monitoring.dbo.Exceptions.exceptionID" could not be bound.
Msg  4104, Level  ##, State  1, Line 3
The multi-part identifier "EXTDATA.Monitoring.dbo.RoomView.exceptionID" could not be bound.

RoomView是一个视图,Exceptions是一个表。

2 个答案:

答案 0 :(得分:2)

加入后似乎是你

SELECT id AS Expr 
FROM EXTDATA.Monitoring.dbo.Exceptions EX
     INNER JOIN EXTDATA.Monitoring.dbo.RoomView RW ON EX.exceptionID = RW.exceptionID

答案 1 :(得分:2)

问题是查询的EXTDATA.Monitoring.dbo.RoomViewFROM子句中未提及JOIN视图。您无法在WHERE子句表达式中引用视图或表格:您需要添加EXISTSJOIN

SELECT id AS Expr 
FROM EXTDATA.Monitoring.dbo.Exceptions e
WHERE EXISTS (
    SELECT * FROM EXTDATA.Monitoring.dbo.RoomView v
    WHERE e.exceptionID = v.exceptionID
)

SELECT DISTINCT id AS Expr
FROM EXTDATA.Monitoring.dbo.Exceptions e
JOIN EXTDATA.Monitoring.dbo.RoomView v ON e.exceptionID = v.exceptionID