select top #url.mi# 'OPR' partnerType, opr.operatorid partnerId, opr.companyname, opr.address, opr.city, opr.state , ter.name as territoryname, opr.oprCompanyType, ter.territoryColor from tbl_opr_clientoperators opr with (nolock) inner join tbl_ter_territories ter with (nolock) on ter.territoryid = opr.territoryid where opr.ownerid = and opr.fsltablecode = and opr.crmActive = 'Y' and opr.buyingDecisions = and opr.territoryId in ( ) and ( ( opr.companyname like or opr.city like ) and 1 = 1 ) union select top #url.mi# 'CDR' partnerType, cdr_recordid partnerId, cdr_dstname companyname, cdr_dstaddress1 address, cdr_dstcity city, cdr_dststate state , ter.name as territoryname, '' as oprCompanyType, ter.territoryColor from tbl_cdr_distributors cdr with (nolock) inner join tbl_ter_territories ter with (nolock) on ter.territoryid = cdr.cdr_territoryId left outer join tbl_DST_Distributors dst on dst.dstid = cdr.FSL_dstid left outer join tbl_DST_Distributors pdst on pdst.dstid = dst.dstparentco where cdr.ownerid = and cdr.fsl_tablecode = and cdr.crmactive = 'Y' and cdr.cdr_dstcompanytype <> 'O' and cdr.cdr_dstcompanytype <> 'S' and cdr.cdr_territoryId in ( ) and ( ( cdr.cdr_dstname like or cdr.cdr_dstcity like ) and 1 = 1 ) and pdst.dstid in () order by companyname #_data#