我的内部联接中有以下“循环依赖”,任何想法如何绕过它?
SELECT *FROM Reference
INNER JOIN ReferenceInActivity ON Activity.ActivityID = ReferenceInActivity.ActivityID
INNER JOIN @tbActivity AS Activity ON ReferenceInActivity.ReferenceID = Reference.ReferenceID
我收到错误: Msg 4104,Level 16,State 1,Line 387 无法绑定多部分标识符“Activity.ActivityID”。
答案 0 :(得分:5)
您在“on”语句中使用Activity,然后在“from”语句或join语句中将其包含在查询中。像这样切换你的“on”语句:
SELECT *
FROM Reference
INNER JOIN ReferenceInActivity
ON ReferenceInActivity.ReferenceID = Reference.ReferenceID
INNER JOIN @tbActivity AS Activity
ON Activity.ActivityID = ReferenceInActivity.ActivityID