brokerId eq -1 select s.ownerId brokerId, s.mfrId, s.skuId, s.sku, p.scc14 gtin, p.upc, s.mfrSkuId, count( distinct isd.interactionId ) interactions from tbl_PRD_Skus s with (nolock) left outer join tbl_PRD_Packaging p with (nolock) on p.linkId = s.skuId and p.linkType = 'SKU' and p.ownerId = s.ownerId and p.fsl_tablecode = s.fsl_tablecode left outer join tbl_CRM_InteractionSaleDetails isd with (nolock) on isd.ownerId = s.ownerId and isd.ownerType = s.fsl_tablecode and isd.saleSubjectType = 'SKU' and isd.saleSubjectId = s.skuId where s.fsl_tablecode = 'BRO' and s.mfrId > 0 and s.ownerId not in ( 2661, 2512, 156 ) and s.sku not like '%$$' and ( nullif( s.mfrSKUId, 0 ) is null or s.mfrSKUIdStatus is null or not exists ( select * from tbl_PRD_SKus s3 where s3.skuId = s.mfrSKUId and s3.ownerId = s.mfrId and s3.fsl_tablecode = 'MFR') ) and coalesce( s.mfrSKUId, 0 ) <> -1 and exists ( select * from tbl_PRD_SKus s2 with (nolock) where s2.ownerId = s.mfrId and s2.fsl_tablecode = 'MFR' ) and exists ( select * from tbl_OFS_BrokerSKUs ofs with (nolock) where ofs.ownerId = s.mfrId and ofs.ownerType = 'MFR') and exists ( select * from tblBrokers b with (nolock) where b.broker_id = s.ownerId ) and exists ( select * from tbl_BRO_Principals ppl with (nolock) inner join tbl_BRO_PrincipalTerritories pt with (nolock) on pt.principalId = ppl.principalId and pt.ownerId = ppl.ownerId and pt.ownerType = ppl.ownerType where ppl.ownerId = s.ownerId and ppl.ownerType = s.fsl_tablecode and ppl.mfrId = s.mfrId and pt.hireStatus = 'A' ) and s.ownerId in ( ) and s.mfrSKUidDate is null group by s.ownerId, s.mfrId, s.skuId, s.sku, p.scc14, p.upc, s.mfrSkuId order by interactions desc