while
   ...
   ...
   ...
end

解决方案 »

  1.   

    結果為:
              102NHA1            102N
              102NHA2            102N
              102NHB1            102NHA1  
              102NHC1            102NHB1  
    有勞  當102N有子類  102N根節點紀錄刪除
      

  2.   

    declare @tmp table (Code varchar(15) , Parent varchar(15))
    insert @tmp
    select Code,Parent from test where Parent = '102N'
    while @@rowcount > 0 begin
    insert @tmp
    select Code,Parent from test where Parent in (select Code from @tmp) and Code not in (select Code from @tmp)
    end
    select * from @tmp
      

  3.   

    cloudchen(cloudchen)  多謝
    請幫忙給我解釋下!