with x as ( select b.ownerId, b.ownertype, count(*) batchCount, row_number() over ( partition by b.ownerType order by count(*) desc ) ranking from tbl_EAI_InboundBatches b with (nolock) where year( b.batchTime ) >= and b.ownerType in ( 'MFR', 'BRO' ) and exists ( select * from tbl_LIB_AccountSettings s with (nolock) where s.ownerId = b.ownerId and s.ownerType = b.ownerType and s.active = 'Y' ) group by ownerId, ownerType ) select *, row_number() over ( order by ranking desc, batchCount ) as reverseOrder from x where ownerid = 2252 and ownerType = 'MFR' order by reverseOrder with x as ( select ownerId, ownertype, count(*) batchCount, row_number() over ( partition by ownerType order by count(*) desc ) ranking from tbl_EAI_InboundBatches with (nolock) where year( batchTime ) >= and ownerType in ( 'MFR', 'BRO' ) group by ownerId, ownerType ) select * from x where ownerId = and ownerType = _processorList = [ "/mstrcfmod/BOM/utilities/utl_applyDataRetentionRules_objectives.cfm", "/mstrcfmod/BPL/utilities/utl_applyDataRetentionRules_broPrincipalResources.cfm", "/mstrcfmod/CRM/utilities/utl_applyDataRetentionRules_interactions.cfm", "/mstrcfmod/SPL/utilities/utl_applyDataRetentionRules_opportunities.cfm", "/mstrcfmod/CDR/utilities/utl_applyDataRetentionRules_distributorSales.cfm", "/mstrcfmod/TPM/utilities/utl_applyDataRetentionRules_tradeData.cfm", "/mstrcfmod/SMPL/utilities/utl_applyDataRetentionRules_smplOrders.cfm", "/mstrcfmod/POS/utilities/utl_applyDataRetentionRules_posOrderManagement.cfm", "/mstrcfmod/PRD/utilities/utl_applyDataRetentionRules_productCatalog.cfm", "/mstrcfmod/TRK/utilities/utl_applyDataRetentionRules_tracking.cfm", "/mstrcfmod/TRN/utilities/utl_applyDataRetentionRules_training.cfm", "/mstrcfmod/SYS/utilities/utl_applyDataRetentionRules_orphans.cfm" ];

#ownerType#:#ownerId#:#encodeforHTML( clientName )#