日期:2014-05-16 浏览次数:20804 次
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
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
go
exec toupdatetb 1