>SELECT Registration.*, Schools.SchoolPhone > FROM dbo.Registration LEFT JOIN Schools ON Registration.School = Schools.School >AND Schools.SiteID = @SiteID > WHERE RegistrationID = @RegistrationID>
>SELECT Registration.*, Schools.SchoolPhone > FROM dbo.Registration LEFT JOIN Schools ON Registration.School = Schools.School >AND Registration.SiteID = Schools.SiteID > WHERE RegistrationID = @RegistrationID>
Registration: SiteId School ------------------------------- 1 1 2 1 3 1 4 2 5 2 Schools: SiteId School ------------------------------- 1 1 2 1So this:
SELECT * FROM Registration LEFT JOIN Schools ON Registration.School = Schools.School AND Registration.SiteId = Schools.SiteIdwill give you this:
Schools: SiteId School SiteId School ------------------------------------- 1 1 1 1 2 1 2 1 3 1 NULL NULL 4 2 NULL NULL 5 2 NULL NULLBut:
DECLARE @SiteId int SET @SiteId = 1 SELECT * FROM Registration LEFT JOIN Schools ON Registration.School = Schools.School AND Schools.SiteId = @SiteIdwill give you this:
Schools: SiteId School SiteId School ------------------------------------- 1 1 1 1 2 1 NULL NULL 3 1 NULL NULL 4 2 NULL NULL 5 2 NULL NULL