select ter.territoryId, ter.name territoryName from tbl_TER_Territories ter inner join tbl_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId and lvl.brokerLevel = 1 and lvl.zipCodeMapping = 'STANDARD' where ter.ownerId = 26 and ter.fsl_tablecode = 'MFR' and exists ( select * from tbl_OPR_ClientOperators opr where opr.ownerId = 26 and opr.fsltablecode = 'MFR' and opr.territoryId = ter.territoryId ) select left( zipCode, 3 ) zip3d, count(*) operatorCount from tbl_OPR_ClientOperators where ownerId = 26 and fsltablecode = 'MFR' and territoryId = group by left( zipCode, 3 )

#htmleditformat( _territoryName )#

Moving #operatorCount# operators in zipcode #zip3d#__ to #htmleditformat( qmd_newTerritory.territoryName )#
update tbl_OPR_ClientOperators set territoryId = , mfr_bsr_Id = 0 where ownerId = 26 and fsltablecode = 'MFR' and territoryId = and left( zipCode, 3 ) =
select p.ownerId, p.ownerType, p.marketingActivityId, opr.territoryId, count( distinct p.operatorId ) participantQuota from tbl_CRM_Participants p inner join tbl_OPR_ClientOperators opr on opr.operatorId = p.operatorId inner join tbl_TER_Territories t on t.territoryId = opr.territoryId where not exists ( select * from tbl_CRM_MarketingActivityTargets mat where mat.marketingActivityId = p.marketingActivityId and mat.territoryId = opr.territoryId ) and p.ownerId = 26 and p.ownertype = 'MFR' and opr.territoryId in ( ) group by p.ownerId, p.ownerType, p.marketingActivityId, opr.territoryId insert into tbl_CRM_MarketingActivityTargets ( ownerId, ownerType, marketingActivityId, territoryId, participantQuota ) values ( , , , , ) select mat.marketingActivityId, mat.territoryId, l.zipCodeMapping, mat.participantQuota, count( distinct opr.operatorId ) participantCount from tbl_CRM_MarketingActivityTargets mat inner join tbl_TER_Territories t on t.territoryId =mat.territoryId inner join tbl_TER_TerritoryLevels l on l.levelId = t.levelId left outer join tbl_CRM_Participants p on p.marketingActivityId = mat.marketingActivityId left outer join tbl_OPR_ClientOperators opr on opr.operatorId = p.operatorId and opr.territoryId = mat.territoryId where mat.ownerId = 26 and mat.marketingActivityId in ( select mat.marketingActivityId from tbl_CRM_MarketingActivityTargets mat inner join tbl_TER_Territories ter on ter.territoryId = mat.territoryId inner join tbl_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId where lvl.ownerId = 26 and lvl.fsl_tablecode = 'MFR' and lvl.zipCodeMapping = 'STANDARD' ) and mat.territoryId in ( ) group by mat.marketingActivityId, mat.territoryId, l.zipCodeMapping, mat.participantQuota update tbl_CRM_MarketingActivityTargets set participantQuota = where territoryId = and marketingActivityId = and ownerId = 26 and ownertype = 'MFR'
#_targetsUpdated# marketing activity territory quotas updated