StructDelete( url, "tid" ); StructDelete( url, "kwd" ); StructDelete( url, "parentdst" ); StructDelete( url, "buyingGroup" ); StructDelete( url, "prty" ); StructDelete( url, "region" ); StructDelete( url, "localmarket" ); StructDelete( url, "cls" ); StructDelete( url, "bsr" ); StructDelete( url, "splStages" ); StructDelete( url, "splEodYear" ); StructDelete( url, "splTaskOpt" ); StructDelete( url, "splTaskTmplId" ); StructDelete( url, "splUserId" ); StructDelete( url, "lastInteractionDays" ); StructDelete( url, "intsts" ); StructDelete( url, "intBsr" ); StructDelete( url, "marketingActivityId" ); StructDelete( url, "marketingActivityCategoryId" ); StructDelete( url, "closeStatus" ); StructDelete( url, "intMfr" ); StructDelete( url, "fp_id" ); StructDelete( url, "fp_catid" ); StructDelete( url, "fp_src" ); StructDelete( url, "fp_mfr" ); StructDelete( url, "fp_skuid" ); StructDelete( url, "fp_bgtcatid" ); StructDelete( url, "fp_qtyFilter" ); StructDelete( url, "mfrbsr2" ); select distinct territoryId from request.qmd_cdrTerritoryHierarchy where parentTerritoryId in () select distinct territoryId from request.qmd_cdrTerritoryHierarchy where parentTerritoryId in () select count(*) matchCount from tbl_CDR_Distributors dst with (nolock) inner join ( select distinct p.partnerid as distrribId, p.ownerId, p.ownerType from tbl_CRM_Participants p with (nolock) inner join tbl_CRM_Interactions i with (nolock) on i.participantId = p.participantId and i.ownerId = p.ownerId and i.ownerType = p.ownerType and i.disposition = and i.disposition = '?' inner join tbl_CRM_InteractionSaleDetails #isdAlias# on #isdAlias#.interactionId = i.interactionId and #isdAlias#.saleSubjectId = and #isdAlias#.disposition in ( 'STD', 'LTO') and #isdAlias#.disposition = and #isdAlias#.nosalereasonId = and i.disposition <> '?' inner join tbl_CRM_MarketingActivities ma with (nolock) on ma.marketingACtivityId = p.marketingActivityId and ma.maCategoryId = where p.ownerId = and p.ownerType = and p.partnerType = 'CDR' and p.marketingActivityId = ) p on p.distrribId = dst.cdr_recordId and p.ownerid = dst.ownerId and p.ownerType = dst.fsl_tableCode where dst.ownerid = and dst.fsl_tableCode = and dst.crmactive = 'Y' and dst.cdr_dstcompanytype <> 'O' and dst.cdr_dstcompanytype <> 'S' and dst.classificationid = and dst.mfr_bsr_id in ( ) and coalesce( dst.mfr_bsr_id, 0 ) = 0 and dst.mfr_bsr_id2 in ( ) and coalesce( dst.mfr_bsr_id2, 0 ) <> 0 AND ( dst.mfr_bsr_id = OR dst.cdr_territoryId in () dst.cdr_territoryId in ( ) dst.cdr_territoryId in ( ) ) and dst.cdr_recordId not in ( select stk.cdr_recordId from tbl_CDR_Stocking stk with (nolock) where stk.ownerId = and stk.ownerType = and stk.volumeQty > 0 and stk.volumetime = 'M' and stk.skuId in ( select sku.skuid from tbl_PRD_Skus sku where sku.ownerId = and sku.FSL_TableCode = and sku.bgtCatID = and sku.skuid = and sku.ProdID = and sku.ProdID in ( select prd.prodId from tbl_PRD_Products prd where prd.ownerId = and prd.FSL_TableCode = and prd.categoryid = ) group by sku.skuid ) group by stk.cdr_recordId having SUM(stk.volumeqty) >= having SUM(stk.volumeqty) <= ) and ( dst.cdr_priority in ( ) 1 = 2 ) and ( dst.lastInteractionDate is not null and datediff( dd, dst.lastInteractionDate, getDate() ) <= ) ( dst.lastInteractionDate is null or datediff( dd, dst.lastInteractionDate, getDate() ) > ) ( dst.lastInteractionDate is null or datediff( dd, dst.lastInteractionDate, getDate() ) > 365 ) and dst.lastInteractionDate is null and dst.cdr_recordId in ( select i.partnerId from tbl_CRM_interactions i with (nolock) inner join tbl_CRM_InteractionSaleDetails isd with (nolock) on isd.interactionId = i.interactionId and isd.saleSubjectType = 'SKU' and isd.ownerId = i.ownerId and isd.ownerType = i.ownerType inner join tbl_PRD_Skus s with (nolock) on s.skuId = isd.saleSubjectId and s.ownerId = i.ownerId and s.fsl_tablecode = i.ownerType and s.mfrId = where i.ownerId = and i.ownerType = and i.partnerType = 'CDR' and i.dispositionUserId = ) and dst.cdr_recordId in ( select i.partnerId from tbl_CRM_interactions i with (nolock) where i.ownerId = and i.ownerType = and i.partnerType = 'CDR' and i.disposition = '?' and i.disposition <> '?' ) and dst.cdr_territoryId in () and dst.cdr_territoryId in ( ) and dst.cdr_territoryId = and dst.cdr_territoryId = -1 and dst.cdr_territoryId in ( ) AND ( dst.cdr_dstname like OR dst.cdr_dststate = OR dst.cdr_dstcity like OR dst.recordSource like OR dst.cdr_dstcode = OR dst.cdr_dstaddress1 like OR dst.cdr_dstaddress2 like OR dst.cdr_dstzip like OR dst.foodservicerewardsId = OR exists ( select * from tbl_CDR_DstCodes cdsc where cdsc.ownerid = dst.ownerid and cdsc.ownerType = dst.fsl_tablecode and cdsc.cdr_recordId = dst.cdr_recordId and cdsc.cdr_dstcode like ) OR dst.cdr_recordId IN () /*SCRUM 44278 - JF - 06/15/2023*/ ) AND ( dst.cdr_dstparentco IN () OR dst.cdr_recordId in ( select cdrb.cdr_recordId from tbl_CDR_Distributors cdrb with (nolock) inner join tbl_DST_Distributors dstb with (nolock) on dstb.dstid = cdrb.fsl_dstid inner join tbl_DST_Distributors dstp with (nolock) on dstp.dstid = dstb.dstparentco inner join tbl_CDR_Distributors cdrp with (nolock) on cdrp.fsl_dstid = dstp.dstid and cdrp.ownerid = cdrb.ownerid and cdrp.fsl_tablecode = cdrb.fsl_tablecode and cdrp.cdr_recordid IN () where cdrb.ownerid = and cdrb.fsl_tablecode = and cdrb.crmactive = 'Y' ) OR cdr_recordID IN () ) AND (( dst.cdr_dstparentco = 0 or dst.cdr_dstparentco is null ) and dst.cdr_dstcompanytype = 'B' ) and dst.cdr_recordId in ( ) AND dst.cdr_recordId in ( select spl.partnerId from tbl_SPL_Opportunities spl with (nolock) inner join tbl_SPL_Stages stg with (nolock) on stg.stageId = spl.stageId and stg.ownerId = spl.ownerId and stg.ownerType = spl.ownerType inner join tbl_WRK_Tasks tsk with (nolock) on tsk.subjectId = spl.opportunityId and tsk.subjectType = 'SPL' and tsk.ownerId = spl.ownerId and tsk.ownerType = spl.ownerType and tsk.disposition in ( 'A', '?' ) and tsk.dueDate <= { fn now() } and tsk.dueDate <= dateadd( day, #_daysAhead#, getDate() ) and tsk.taskTemplateId = where spl.partnerType = 'CDR' and spl.ownerId = and spl.ownerType = and spl.stageId in ( ) and spl.availableDate between and and spl.salesPersonUserId = and datepart( yy, case when stg.statusCode = 'C' or stg.statusCode = 'I' then spl.availableDate when stg.statusCode = 'A' then getDate() when stg.statusCode = 'R' then spl.availableDate else coalesce( spl.updateDate, spl.createDate ) end ) + 3 > datepart( yy, getdate() ) ) AND dst.cdr_recordId in ( select pl.partnerId from tbl_LST_PartnerListItems pl with (nolock) where pl.listId = )