try this:
DECLARE @YourTable table (id int, Comment varchar(10), parentID int)
INSERT INTO @YourTable VALUES (3, 't1' , NULL)
INSERT INTO @YourTable VALUES (4, 't2' , NULL)
INSERT INTO @YourTable VALUES (5, 't1_1' , 3)
INSERT INTO @YourTable VALUES (6, 't2_1' , 4)
INSERT INTO @YourTable VALUES (7, 't1_1_1', 5)
;with c as
(
SELECT id, comment, parentid, CONVERT(varchar(8000),RIGHT('0000000000'+CONVERT(varchar(10),id),10)) as SortBy
from @YourTable
where parentID IS NULL
UNION ALL
SELECT y.id, y.comment, y.parentid, LEFT(c.SortBy+CONVERT(varchar(8000),RIGHT('0000000000'+CONVERT(varchar(10),y.id),10)),8000) AS SortBy
FROM c
INNER JOIN @YourTable y ON c.ID=y.PArentID
)
select * from C ORDER BY SortBy
EDIT
here is output
id comment parentid SortBy
----------- ---------- ----------- ---------------------------------
3 t1 NULL 0000000003
5 t1_1 3 00000000030000000005
7 t1_1_1 5 000000000300000000050000000007
4 t2 NULL 0000000004
6 t2_1 4 00000000040000000006
(5 row(s) affected)