myAttrs.ownerId = client.ownerId; myAttrs.ownerType = client.ownerType; myAttrs.datasource = client.datasource; myAttrs.queryName = "qmd_distributors"; myAttrs.endRow = 0; // why are there two of these myAttrs.territoryId = attributes.territoryId; myAttrs.dst_territory = attributes.territoryId; // search specific filtering goes here myAttrs.dst_keyword = client.dst_keyword; myAttrs.dst_cls = client.dst_cls; myAttrs.dst_parent = client.dst_parent; myAttrs.dst_prty = client.dst_prty; myAttrs.splStages = client.dst_splStages; myAttrs.splEodYear = client.dst_splEodYear; myAttrs.splTaskOpt = client.dst_splTaskOpt; myAttrs.splTaskTmplId = client.dst_splTaskTmplId; myAttrs.splUserId = client.dst_splUserId; myAttrs.lastInteractionDays = client.dst_lastInteractionDays; myAttrs.intsts = client.dst_intsts; myAttrs.intBsr = client.dst_intBsr; myAttrs.marketingActivityId = client.dst_event; myAttrs.marketingActivityCategoryId = client.dst_maCategoryId; myAttrs.intMfr = client.dst_intMfr; myAttrs.fp_id = client.dst_fp_id; myAttrs.fp_catid = client.dst_fp_catid; myAttrs.fp_src = client.dst_fp_src; myAttrs.fp_mfr = client.dst_fp_mfr; myAttrs.fp_skuid = client.dst_fp_skuid; myAttrs.fp_bgtcatid = client.dst_fp_bgtcatid; myAttrs.fp_qtyFilter = client.dst_fp_qtyFilter; myAttrs.dst_parent = client.dst_parent; myAttrs.affiliates = _affiliates; myAttrs.customerManagerUserId = client.dst_bsr; myAttrs.mfrbsr2 = client.dst_mfrbsr2; // ??? what are these for ??? myAttrs.pri_lead = variables.pri_lead; myAttrs.ownedTerritoryList = request.ownedTerritoryList; select m.fspro_userid, m.firstName, m.lastName, m.title, 'TeamMember' teamMemberRole, count(*) distributorCount, case when m.fspro_userid is null then 1 else 0 end defaultOwner, 1 teamMember from tbl_CDR_Distributors cdr left outer join tbl_FSPro_Members m on m.fspro_userid = cdr.mfr_bsr_id and m.ownerId > 0 where cdr.ownerId = and cdr.fsl_tablecode = and cdr.crmActive = 'Y' and cdr.cdr_territoryId = and cdr.cdr_recordId in ( #_distributorIds# ) group by m.fspro_userid, m.firstName, m.lastName, m.title order by defaultOwner desc, teamMember, lastName, firstName #htmleditformat( request.portalConfiguration.apps.102.unassignedLabel )# #htmleditformat( firstname )# #htmleditformat( lastName )# - #htmleditformat( title )# #distributorCount#