SqlServer实现递归查询

之前一直用Oracle,一下子换到了Sql,有些语法还真不熟悉,再次记录一下:

with t1 as ( select a.dptname,a.parentid,a.deptid,a.status,a.typecode from base_dept a where a.deptid=2 union all select  d.dptname,d.parentid,d.deptid,d.status,d.typecode from base_dept d inner join base_dept c on d.parentid=c.deptid ) select * from t1

posted @ 2012-07-29 17:00  SmartBooks  阅读(446)  评论(0编辑  收藏  举报