Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Conditional 3 Table Join

Author  Topic 

Rohan.cmu
Starting Member

1 Post

Posted - 2014-05-06 : 00:52:24
Table 1

PropertyId

1
2
3
4
5
6

Table 2

PropertyID PropertyCode PropList ID

1 2 45
3 4 67
5 6 89

Table 3

PropertyID IType

1 3
2 3
3 11
4 11
5 3
6 3

Target Table

PropertyID PropertyCode

1 45
2 45
3 67
4 67
5 89
6 89
Step1: Join Table 1 and Table 3

Steo 2: If Table 1.PropertyId.Itype = 3 Then Join Table 1 and Table 3 on Table1.PropertyID = Table2.PropertyId

Else

Step 3: If Table 1.PropertyId.Itype = 11 Then Join Table 1 and Table 2 on Table1.PropertyID = Table2.PropListId

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-05-06 : 07:23:36
What have you tried so far?

Note that your "Step 2" doesn't make sense, since table 3 does not have a PropertyCode column.
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-05-06 : 08:52:13
quote:
Originally posted by gbritton

What have you tried so far?

Note that your "Step 2" doesn't make sense, since table 3 does not have a PropertyCode column.

Also, Table 1 has PropertyCode as the second column, but your expected results shows values from the PropListID column instead.

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2014-05-06 : 09:25:06
But my homework needs done now!








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-05-06 : 09:30:31
quote:
Originally posted by DonAtWork

But my homework needs done now!


How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx





Yeah! I have problems answering folks homework questions:

1. Usually ridiculously simple and contrived
2. If I post an answer, what does the student learn?
Go to Top of Page
   

- Advertisement -