select distinct ap.affiliationOrgId, companyname from tbl_CRM_AffiliationProducts ap inner join tbl_OPR_ClientOperators opr on opr.operatorId = ap.affiliationOrgId where ap.linkType = 'MFR' and ap.linkid in () and ( ap.startdate is null or startdate <= getdate() ) and ( ap.enddate is null or enddate >= getdate() ) and opr.ownerId = and opr.fsltablecode = order by companyname