select mDst.cdr_dstcode as mfrDstCode, mDst.cdr_territoryId as mfrTerritoryId, bDst.cdr_recordId as broCdrRecordId, bDst.cdr_dstName as broCdrDstName from tbl_CDR_Distributors mDst inner join tbl_CDR_Distributors bDst on mDst.fsl_dstid = bDst.fsl_dstid where mDst.ownerId = and mDst.fsl_tablecode = and mDst.cdr_territoryId IN ( select distinct bol.territoryId from tbl_SMA_BrokerOfficeLink bol inner join tbl_TER_Territories ter on ter.territoryId = bol.territoryId and ter.ownerId = bol.mfr_id and ter.fsl_tablecode = inner join tbl_BRO_PrincipalTerritories pTer on pTer.mfrTerritoryNbr = ter.internalSalesId and pTer.ownerId = bol.brokerId where bol.TerritoryId > 0 and bol.brokerId = and bol.mfr_id = and pTer.principalId = ) and bDst.fsl_tablecode = and bDst.ownerId = and mDst.fsl_tablecode = and mDst.ownerId = and mDst.FSL_masterlinkYN = 'Y' and bDst.fsl_dstId > 0 and mDst.fsl_dstId > 0 and bDst.crmActive = 'Y' and mDst.crmActive = 'Y' and mDst.cdr_dstcode is not null and mDst.cdr_dstCode != '' select pDst.mfrCustNbr, pDst.cdrRecordId, pTer.principalTerritoryId, ter.name from tbl_BRO_PrincipalTerritories pTer inner join tbl_TER_Territories ter on ter.internalSalesId = pTer.mfrTerritoryNbr inner join tbl_BRO_PrincipalDistributors pDst on pDst.principalTerritoryId = pTer.principalTerritoryId and pDst.cdrRecordId = where pTer.ownerId = and pTer.ownerType = and pTer.principalId = and ter.territoryId = and ter.ownerId = and ter.fsl_tablecode = select pTer.principalTerritoryId, ter.name from tbl_BRO_PrincipalTerritories pTer inner join tbl_TER_Territories ter on ter.internalSalesId = pTer.mfrTerritoryNbr where pTer.ownerId = and pTer.ownerType = and pTer.principalId = and ter.territoryId = and ter.ownerId = and ter.fsl_tablecode = select pDst.cdrRecordId, pTer.principalTerritoryId, ter.territoryId, ter.name from tbl_BRO_PrincipalDistributors pDst inner join tbl_BRO_PrincipalTerritories pTer on pTer.principalTerritoryId = pDst.principalTerritoryId and pTer.ownerId = pDst.ownerId and pTer.ownerType = pDst.ownerType inner join tbl_TER_Territories ter on ter.internalSalesId = pTer.mfrTerritoryNbr and ter.ownerId = and ter.fsl_tablecode = 'MFR' where pDst.cdrRecordId = and ter.territoryId IN ( select distinct bol.territoryId from tbl_SMA_BrokerOfficeLink bol inner join tbl_TER_Territories ter on ter.territoryId = bol.territoryId and ter.ownerId = bol.mfr_id and ter.fsl_tablecode = inner join tbl_BRO_PrincipalTerritories bTer on bTer.mfrTerritoryNbr = ter.internalSalesId and bTer.ownerId = bol.brokerId where bol.TerritoryId > 0 and bol.brokerId = and bol.mfr_id = and bTer.principalId = ) and pDst.ownerId = and pDst.ownerType = UPDATE tbl_BRO_PrincipalDistributors set mfrCustNbr = , principalTerritoryId = , recordSource = 'Distributor Moved - #qmd_batch.batchId#' WHERE ownerId = and ownerType = and cdrRecordId = INSERT INTO tbl_BRO_PrincipalDistributors (ownerId, ownerType, principalTerritoryId, cdrRecordId, mfrCustNbr, focusAccount, createDate, recordSource ) VALUES ( , , , , , , {fn now()}, ) update tbl_BRO_PrincipalDistributors set mfrCustNbr = , recordSource = where ownerType = and principalTerritoryId = and cdrRecordId =
ActionDistributorMFR Account Nbr
Moved#broCdrDstName# ( #broCdrRecordId# )#mfrDstCode#
 Moved from #qmd_distributorExists.name# to #qmd_lookupTerritory.name#
Added#broCdrDstName# ( #broCdrRecordId# )#mfrDstCode#
 Added under #qmd_lookupTerritory.name#
Updated#broCdrDstName# ( #broCdrRecordId# )#mfrDstCode#
 #qmd_principalDistributor.mfrCustNbr# to #mfrDstCode#
No Change#broCdrDstName# ( #broCdrRecordId# )#mfrDstCode#