select distinct e.territoryid from tbl_EVT_Events e where e.ownerid = and e.ownerType = select * from request.qmd_userTerritoryHierarchy where territoryid in () where 1 = 1 order by territoryname