Try this code in Query Analyser. It enough for small data. If you want to use for big data, modify the code.
SET nocount ON
CREATE TABLE #tmpName (ID int, [Name] varchar(255))
CREATE TABLE #tmpRelation (ID int, ID_Parent int)
INSERT #tmpName (ID, [Name]) select 1, 'Frank'
INSERT #tmpName (ID, [Name]) select 2, 'Jo'
INSERT #tmpName (ID, [Name]) select 3, 'Mary'
INSERT #tmpName (ID, [Name]) select 4, 'Peter'
INSERT #tmpName (ID, [Name]) select 5, 'Amy'
INSERT #tmpRelation (ID, ID_Parent) select 1, 0
INSERT #tmpRelation (ID, ID_Parent) select 2, 1
INSERT #tmpRelation (ID, ID_Parent) select 3, 2
INSERT #tmpRelation (ID, ID_Parent) select 4, 1
INSERT #tmpRelation (ID, ID_Parent) select 5, 2
CREATE TABLE #tmpResult (ID int, ID_Parent int, [Level] int, [Name] varchar(255))
INSERT #tmpResult (ID, ID_Parent, [Level], [Name])
SELECT N.ID, R.ID_Parent, 0, N.[Name]
FROM #tmpName N inner join #tmpRelation R on
N.ID = R.ID
WHERE ID_Parent = 0
while EXISTS (SELECT 1 FROM #tmpName N left join #tmpResult R on N.ID = R.ID where R.ID is null)
begin
INSERT #tmpResult (ID, ID_Parent, [Level], [Name])
SELECT N.ID, R.ID_Parent, C.[Level] + 1, N.[Name]
FROM #tmpName N inner join #tmpRelation R on
N.ID = R.ID INNER JOIN (
SELECT P.ID, P.[Level]
FROM #tmpResult P left join #tmpResult C on
P.ID = C.ID_Parent
WHERE C.ID IS NULL
) C ON
R.ID_Parent = C.ID
end
SELECT ID, [Level], Name FROM #tmpResult
DROP TABLE #tmpResult
DROP TABLE #tmpName
DROP TABLE #tmpRelation