通过调整绿色区域,改变查询子、父级。注意分号,注意取完立即赋值到临时表。
;with parentData as
(
select ID,ParentId,Name from PJ_ScheduleItem where ID=@ID
union all
select b.ID,b.ParentId,b.Name from parentData a, PJ_ScheduleItem b
where a.ParentId=b.ID and b.Status= 0
)
select * into #pd from parentData;