SQL 樹狀結構表中查出所所有父級/子級


通過調整綠色區域,改變查詢子、父級。注意分號,注意取完立即賦值到臨時表。

;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;	

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM