Вы не можете с ROW_NUMBER (). Вам нужно использовать рекурсивный CTE и создать синтетический порядок сортировки, составив полный родительский путь:
declare @table table (row int, par int, lev int, has_child bit);
insert into @table
select 1, NULL, 0, 1
union all select 2, 1, 1, 1
union all select 3, 1, 1, 1
union all select 4, 1, 1, 1
union all select 5, 1, 1, 1
union all select 6, 1, 1, 0
union all select 148, 2, 2, 0
union all select 149, 2, 2, 1
union all select 145, 3, 2, 0
union all select 146, 3, 2, 1
union all select 9, 4, 2, 0
union all select 11, 4, 2, 0
union all select 12, 4, 2, 0
union all select 13, 4, 2, 0
union all select 14, 4, 2, 0
union all select 15, 4, 2, 0
union all select 16, 4, 2, 0
union all select 17, 4, 2, 0;
with cte_anchor as (
select row, par, 0 as lev, cast(row as varchar(max)) as wbs
from @table
where par is null)
, cte_recursive as (
select row, par, lev, wbs
from cte_anchor
union all
select t.row, t.par, r.lev+1 as lev
, r.wbs + '.' + cast(t.row as varchar(max)) as wbs
from @table t
join cte_recursive r on t.par = r.row)
select * from cte_recursive
order by wbs