Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a table to a view in another DB

Status
Not open for further replies.

SheepDog

Programmer
Feb 4, 2003
232
0
0
US
I have the following code and need help in creating a left outer join with the People table using People_Code_ID as the join. Here is the dba db and table name.
dbo.Institute.Prospect_Recruiter.

SELECT DISTINCT
dbo.PEOPLE.PEOPLE_ID, dbo.PEOPLE.FIRST_NAME, dbo.PEOPLE.LAST_NAME, dbo.ACADEMIC.ACADEMIC_YEAR, dbo.ACADEMIC.ACADEMIC_TERM,
dbo.ADDRESS.ADDRESS_LINE_1, dbo.ADDRESS.STATE, dbo.ADDRESS.CITY, dbo.ADDRESS.ZIP_CODE, dbo.ADDRESS.DAY_PHONE,
dbo.ADDRESS.EVENING_PHONE, dbo.ADDRESS.EMAIL_ADDRESS, dbo.volunteer_interest.people_code_id,
dbo.volunteer_interest.last_name AS Recruiter_LName, dbo.volunteer_interest.first_name AS Recruiter_FName,
dbo.volunteer_interest.address_line_1 AS RecruiterAdd, dbo.volunteer_interest.city AS Recruiter_City, dbo.volunteer_interest.state AS Recruiter_State,
dbo.volunteer_interest.zip_code AS Recruiter_Zip_Code, dbo.volunteer_interest.email_address AS Recruiter_Email,
dbo.ACADEMIC.APP_DECISION
FROM dbo.PEOPLE LEFT OUTER JOIN
dbo.ADDRESS ON dbo.PEOPLE.PREFERRED_ADD = dbo.ADDRESS.ADDRESS_TYPE AND
dbo.PEOPLE.PEOPLE_CODE_ID = dbo.ADDRESS.PEOPLE_ORG_CODE_ID LEFT OUTER JOIN
dbo.ACADEMIC ON dbo.PEOPLE.PEOPLE_CODE_ID = dbo.ACADEMIC.PEOPLE_CODE_ID LEFT OUTER JOIN
Institute.dbo.SemesterInfo Sem ON dbo.ACADEMIC.ACADEMIC_YEAR = Sem.academic_year RIGHT OUTER JOIN
dbo.volunteer_interest ON dbo.ADDRESS.CITY = dbo.volunteer_interest.city AND dbo.ADDRESS.STATE = dbo.volunteer_interest.state
WHERE (dbo.ACADEMIC.ACADEMIC_FLAG = 'n') AND (dbo.ACADEMIC.APPLICATION_FLAG = 'y') AND (Sem.offset = '0') AND
(dbo.ACADEMIC.APP_DECISION <> 'CX' OR
dbo.ACADEMIC.APP_DECISION = 'REJ')
 
If you reference a left outer joined tables in the where clause it will turn it into an inner join as null = x is always false

so instead of

from a
left join b
on a.x = b.x
where b.z = 'q'

code

from a
left join b
on a.x = b.x
and b.z = 'q'


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top