select t1.id, t1.name, @FartherId = t1.FartherID
from 信息表 t1  
left join 菜單表 t2 on t1.id = t2.id
where t2.id = 'idnumber'while isnull(@Fartherid,'') <> '' 
begin
--顯示上級id
select t1.id, t1.name, @FartherId = t1.FartherID
from 信息表 t1  
left join 菜單表 t2 on t1.id = t2.id
where t2.id = FartherId end