通過調整綠色區域,改變查詢子、父級。注意分號,注意取完立即賦值到臨時表。
;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;