SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Conditional 3 Table Join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rohan.cmu
Starting Member

1 Posts

Posted - 05/06/2014 :  00:52:24  Show Profile  Reply with Quote
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
Aged Yak Warrior

863 Posts

Posted - 05/06/2014 :  07:23:36  Show Profile  Reply with Quote
What have you tried so far?

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

Edited by - gbritton on 05/06/2014 08:49:47
Go to Top of Page

gbritton
Aged Yak Warrior

863 Posts

Posted - 05/06/2014 :  08:52:13  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 05/06/2014 :  09:25:06  Show Profile  Reply with Quote
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
Aged Yak Warrior

863 Posts

Posted - 05/06/2014 :  09:30:31  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.33 seconds. Powered By: Snitz Forums 2000