sql递归查询

--获得上级
with my as
(
select * from TB_Area where AreaID=72344566572777472
union all
select aa.* from my,TB_Area aa where my.ParentID=aa.AreaID
) select * from my
go
--获得下级
with my as
(
select * from TB_Area where AreaID=72339069014638592
union all
select aa.* from my,TB_Area aa where my.AreaID=aa.ParentID
) select * from my

 

posted @ 2012-11-13 16:43  一千零一夜  阅读(146)  评论(0编辑  收藏  举报