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