开发者

How do I get around a 'circular reference' in an Inner join

开发者 https://www.devze.com 2022-12-09 12:32 出处:网络
I have the following \'circular dependency\' in my Inner Join, any ideas how to get round it? SELECT *FROM Reference

I have the following 'circular dependency' in my Inner Join, any ideas how to get round it?

SELECT *FROM Reference 
INNER JOIN ReferenceInActivity ON Activity.ActivityID = ReferenceInActivity.ActivityID 
INNER JOIN @tbActivity AS Activity ON ReferenceInActivity.ReferenceID = Reference.ReferenceID 

I get th开发者_StackOverflowe error: Msg 4104, Level 16, State 1, Line 387 The multi-part identifier "Activity.ActivityID" could not be bound.


You are using Activity in the "on" statement before you've included it in the query in the "from" statement or a join statement. Switch your "on" statements around like this:

SELECT     * 
FROM       Reference 
INNER JOIN ReferenceInActivity 
ON         ReferenceInActivity.ReferenceID = Reference.ReferenceID
INNER JOIN @tbActivity AS Activity 
ON         Activity.ActivityID = ReferenceInActivity.ActivityID 
0

精彩评论

暂无评论...
验证码 换一张
取 消