select ter.territoryId, ter.name territoryName from tbl_TER_Territories ter inner join tbL_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId where ter.ownerId = and ter.fsl_tablecode = and ter.territoryId = 0 select 'OPR' rec_type, o.operatorId external_id, 'FSE' external_id_type, 'Food Service Enablers' external_id_owner, o.companyName company_name, o.city company_city, o.address company_address1, o.address2 company_address2, o.state company_state, o.zipcode company_zip, o.phone company_phone, o.faxNumber company_fax, ao.companyName affiliation_orgname, a.partnerAffiliateNbr affiliate_nbr from tbl_OPR_ClientOperators o left outer join tbl_CRM_Affiliations a on a.partnerId = o.operatorId and a.partnerType = 'OPR' and a.affiliationStatus = 'A' and a.orgType = 'OPR' and a.ownerId = o.ownerId and a.ownerType = o.fsltablecode left outer join tbl_OPR_ClientOperators ao on ao.operatorId = a.orgId and ao.ownerId = a.ownerId and ao.fsltablecode = a.ownerType and ao.crmActive = 'Y' where o.ownerId= and o.fsltablecode = and coalesce( o.territoryId, 0 ) = and o.operatorId not in ( select partnerId from tbl_CRM_Participants where marketingActivityId in ( 1219,1224,1220,1222,1221,1223 ) and partnerType = 'OPR' ) select jobFunctionName from tbl_OPR_JobFunctions where ownerId = and ownerType = and jobFunctionId = --->