select bpl.principalId, m.mfr_id mfrId, m.mfr_name mfrName, priority mfrPriority, sortRank mfrSortRank, case when priority = '*' then 0 when priority = 'A' then 1 when priority = 'B' then 2 when priority = 'C' then 3 when priority = 'D' then 4 else 5 end mfrPriorityRank from tbl_BRO_Principals bpl inner join tblManufacturers m on m.mfr_id = bpl.mfrId where bpl.ownerId = and bpl.ownerType = order by mfrPriorityRank, mfrSortRank, mfrName select pt.hireStatus, pt.mfrTerritoryNbr, pt.mfrTerritoryName, pt.principalTerritoryId, pt.hireStatus, ptr.resourceId territoryId from tbl_BRO_PrincipalTerritories pt left outer join tbl_BRO_PrincipalTerritoryResources ptr on ptr.principalTerritoryId = pt.principalTerritoryId and ptr.ownerId = pt.ownerId and ptr.ownerType = pt.ownerType and ptr.resourceType = 'TER' where pt.principalId = and pt.ownerId = and pt.ownerType = select *, upper( mfrName ) nameSort from qmd_matrix where activeMarkets > 0 and ( m_#_tid# = '#_filterValue#' or m_#_tid# is null ) order by mfrPriorityRank, mfrSortRank, nameSort select distinct parentTerritoryId from request.qmd_userTerritoryHierarchy where territoryId in ( ) select territoryId, name territoryName from tbl_TER_Territories where territoryId in ( ) and ownerId = and fsl_tablecode = order by territoryName select * from request.qmd_userTerritoryHierarchy where parentTerritoryId IN () order by displayOrder