select ter.territoryId, ter.name from tbl_TER_Territories ter inner join tbl_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId where ter.ownerId = and ter.fsl_tablecode = and lvl.rank in ( 1, 2 ) order by lvl.rank, ter.name
select m.FSPro_UserID, m.FirstName, m.lastName, m.title, m.email, m.lastLoginDate, count( distinct ter.territoryId ) territoryCount from tbl_TER_TeamMembers t inner join tbl_FSPro_Members m on m.FSPro_UserID = t.teamMemberUserId inner join tbl_TER_Territories ter on ter.TerritoryID = t.territoryId where t.ownerId = #url.ownerId# and t.ownerType = '#url.ownerType#' and t.territoryId in ( #_territoryIds# ) and (( exists ( select opr.operatorId opr from tbl_OPR_ClientOperators opr where opr.TerritoryID = t.territoryId and opr.CRMActive = 'Y' union select cdr.cdr_recordId from tbl_CDR_Distributors cdr where cdr.cdr_territoryid = t.territoryId and cdr.CRMActive = 'Y' ) ) or ( exists ( select opr.operatorId opr from tbl_OPR_ClientOperators opr where opr.mfr_bsr_id = t.teamMemberUserId and opr.CRMActive = 'Y' union select cdr.cdr_recordId from tbl_CDR_Distributors cdr where cdr.mfr_bsr_id = t.teamMemberUserId and cdr.CRMActive = 'Y' ) )) and m.lastLoginDate is not null and m.lastLoginDate is null group by m.FSPro_UserID, m.FirstName, m.lastName, m.title, m.email, m.lastLoginDate order by m.LastName, m.FirstName select TOP 1 ter.Name from tbl_TER_TeamMembers t inner join tbl_TER_Territories ter on ter.TerritoryID = t.territoryId where t.ownerId = #url.ownerId# and t.ownerType = '#url.ownerType#' and t.teamMemberUserId = #fspro_userid#
#lsnumberformat( qmd_customerManagers.recordCount )# Customer Managers
Name Title Email Last Login Ter. Count Territory Name
#htmleditformat( lastName )#, #htmleditformat( firstName )# #Title# #htmleditformat( email )# #lsDateFormat( lastLoginDate, "mm/dd/yyyy")# #lsnumberformat( territoryCount )# #qmd_TerritoryName.Name#