with data as ( select distinct territoryId, territoryName, territoryPath from tbl_DW_OperatorTerritories#_tableSuffix# with (nolock) where ownerId = and ownerType = and territoryId in ( ) ) select count(*) over() as fseRowCount, * from data where territoryId in ( ) #applyFilter( _dataStore.filter )# and #applyFilter( _dataStore.search )# order by territoryName offset #_dataStore.skip# rows fetch next #_dataStore.take# rows only for json auto, include_null_values