不需要把值都赋为1,我只需要能sql语句把这几条查出来就行了

解决方案 »

  1.   


    with testcte as
    (
    select ID,ParentID,[Delete] from Test where ID=1
    union all
    select t.ID,t.ParentID,t.[Delete] from testcte as tc
    join Test as t on t.ParentID=tc.ID
    )update Test set [Delete]=1
    where ID in(select ID from testcte)
       --结果:
       --ID ParentID Delete
       --1   NULl      1
       --2    1        1 
       --3    1        1
       --4   2        1 
      

  2.   


    create table Test
    (
    ID int null,
    ParentID int null,
    [Delete] int null
    )
    insert Test
    select 1,null,0 union all
    select 2,1,0 union all
    select 3,1,0 union all
    select 4,2,0 
      

  3.   

    查询分析器里我写
    insert   table
    select  1  union all
    查不出呢
      

  4.   


    create procedure toupdatetb(@id int)
    as
    begin
        ;with cte as
        (
        select ID,ParentID,[Delete] from Test where ID=@id
        union all
        select t.ID,t.ParentID,t.[Delete] from testcte as tc
        join Test as t on t.ParentID=tc.ID
        )    update Test set [Delete]=1
        where ID in(select ID from testcte)
    end
    goexec toupdatetb 1