Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-06-27 : 09:19:08
|
Adam writes "Sql Server 2000Windows 2000 serverHaving trouble with nested multiple outer joins.Found this syntax online but returns errors.Select A.emailid,A.email,A.firstname,a.middleinitial,a.lastname,a.phone,a.address,a.aptnumber,a.city,a.state,a.zip,a.age,c.gender,f.maritalstatus,d.income,e.credit,I.residence,B.education,h.occupation,g.numchildren,a.bitfieldcat from ((((((((EmailAddresses a1 left outer join educationmapping B on (a1.education = b.educationid)) a2left outer join gendermapping C on (a2.gender = c.genderid)) a3left outer join Incomemapping D on (a3.annualincome = d.incomeid)) a4left outer join creditmapping E on (a4.credithistory = e.creditid)) a5left outer join maritalstatusmapping F on (a5.maritalstatus = f.maritalid)) a6left outer join numchildrenmapping G on (a6.children = g.childrenid)) a7left outer join occupationmapping H on (a7.occupation = h.occupationid)) a8left outer join residencemapping I on (a8.residencestatus = i.residenceid)) awhere ((1 & a.BitFieldCat) > 0)" |
|
MakeYourDaddyProud
184 Posts |
Posted - 2002-06-27 : 09:23:52
|
... sniff, sniff, sniff. I can smell an Access query. Try removing all the braces and indenting as a first course of action.Daniel Small MIAPwww.danielsmall.com IT Factoring |
|
|
acollins74
Yak Posting Veteran
82 Posts |
Posted - 2002-06-27 : 10:04:12
|
Still Can't seem to find the correct syntax for mult. outer joins. Daniel's help was wonderful but something a little more specific would be nice also. |
|
|
MakeYourDaddyProud
184 Posts |
Posted - 2002-06-27 : 10:56:40
|
Try this after your whole select listFROMEmailAddresses a1 left outer join educationmapping B on a1.education = b.educationidleft outer join gendermapping C on B.gender = c.genderidleft outer join Incomemapping D on C.annualincome = d.incomeidleft outer join creditmapping E on D.credithistory = e.creditidleft outer join maritalstatusmapping F on E.maritalstatus = f.maritalidleft outer join numchildrenmapping G on F.children = g.childrenid left outer join occupationmapping H on G.occupation = h.occupationidleft outer join residencemapping I on H.residencestatus = i.residenceidHTHDaniel Small MIAPwww.danielsmall.com IT Factoring |
|
|
acollins74
Yak Posting Veteran
82 Posts |
Posted - 2002-06-27 : 14:17:35
|
Ok, This will not work b/c the mapping tables are not related to each other. The join must be nested. The mapping tables are related to the EmailAddresses table by the ID columns in the mapping tables. The database is set up this way because an everchanging asp page calls the mapping tables to populate several drop downs dynamically.I appreciate your help! |
|
|
MakeYourDaddyProud
184 Posts |
Posted - 2002-06-27 : 14:38:11
|
Can you post column lists of the mapping & email addresses tables? I can work this out for you.Daniel Small MIAPwww.danielsmall.com IT Factoring |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2002-06-27 : 14:38:23
|
I disagree with you that the joins must be nested. The parentheses in a FROM clause are optional (and in fact not desirable because they cause the SQL Server optimizer to consider a particular join order; see Rob's comments ) and you can write functionally equivalent expressions without them.Post your DDL and describe in more detail how the data is structured.Jonathan Boott, MCDBAEdited by - setbasedisthetruepath on 06/27/2002 14:38:58 |
|
|
acollins74
Yak Posting Veteran
82 Posts |
Posted - 2002-06-27 : 15:19:39
|
Hope this is enough information.EMAILADDRESSESEmailID bigint Email varcharRemoveRequest charFirstName varcharMiddleInitial varcharLastName varcharPhone varcharAddress varcharAptNumber varcharCity varcharState charZip varcharAge intGender bitMaritalStatus intCreditHistory intResidenceStatus intAnnualIncome intEducation intOccupation intChildren intBitFieldCat intCounter intMaxAllowed intDateTime datetimeMAPPING TABLESId intName varcharmapping tables prepopped..eg:OCCUPATIONMAPPINGId Name1 Consultant2 Farmer..15 SingerCREDITHISTORYMAPPINGId Name1 Excellent2 Good3 Average4 Pooretc... |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2002-06-28 : 15:36:55
|
Try this:from EmailAddresses a1 left outer join educationmapping B on a1.education = b.id left outer join gendermapping C on convert(int, a1.gender) = c.id left outer join Incomemapping D on a1.annualincome = d.id left outer join creditmapping E on a1.credithistory = e.id left outer join maritalstatusmapping F on a1.maritalstatus = f.id left outer join numchildrenmapping G on a1.children = g.id left outer join occupationmapping H on a1.occupation = h.id left outer join residencemapping I on a1.residencestatus = i.idEdited by - drymchaser on 06/28/2002 15:38:43 |
|
|
acollins74
Yak Posting Veteran
82 Posts |
Posted - 2002-07-01 : 09:06:43
|
Crazy Thanks to Drymchaser.Works Great! |
|
|
|