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.
| Author |
Topic |
|
BradleyGZ
Starting Member
4 Posts |
Posted - 2011-02-04 : 11:26:37
|
| I am joining 4 tables. 3 of these tables will always have linking data. (DatEmployee will always have a linked record in RefDepartment and RefTitle) However, there will not always be a record in DatAlias. If there is then I want that value but only is a bit field is set to true. Here is my statement.SELECT dbo.DatEmployee.*, dbo.RefDepartment.DeptName, dbo.RefDepartment.DeptNum, dbo.RefTitle.JobTitle, dbo.RefTitle.WorkCompRef, dbo.DatAlias.AliasFROM dbo.DatEmployee INNER JOIN dbo.RefDepartment ON dbo.DatEmployee.HomeDeptRef = dbo.RefDepartment.DeptRef INNER JOIN dbo.RefTitle ON dbo.DatEmployee.HomeTitleRef = dbo.RefTitle.TitleRef LEFT OUTER JOIN dbo.DatAlias ON dbo.DatEmployee.TinNum = dbo.DatAlias.TinNumWHERE (dbo.DatAlias.IsSSAName = 1)This wont return anything if there is not a record in DatAlias with IsSSAName = True.Thanks in advanced.Brad. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-04 : 11:30:21
|
| Change the WHERE to AND se if that worksJimEveryday I learn something that somebody else already knew |
 |
|
|
BradleyGZ
Starting Member
4 Posts |
Posted - 2011-02-04 : 11:35:37
|
| Thanks for the quick response Jim.That worked. I never would have figured that simple one out.Thanks again! |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-04 : 11:45:16
|
| You're welcome. You can Google Join vs Where and find some good articles on why this worked.JimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|