JOIN dbSecurity.dbo.AccountInstSecurityRole s ON s.InstitutionID = CASE WHEN (RecordCount) <= 1 THEN v.ParentInstitutionID ELSE v.InstitutionID END