2010-04-13 15:00
select * into t from (select 1 as id,'中国' as [name],0 as parentId union allselect 2,'江西',1 union allselect 3,'浙江',1 union allselect 4,'杭州',3 union allselect 5,'南昌',2 union allselect 6,'桐乡',4 union allselect 7,'桐炉',4 union allselect 8,'进贤',5 union allselect 9,'东湖区',5 union allselect 10,'建德',4) as temp--select * from t;;with tree(id,name,parentID) as--//括号内的内容也可以不要。相当于传递给方法的参数 (select id,[name],parentID from t where [name] = '浙江'union allselect t.id,t.[name],t.parentID from t inner join tree on t.parentID = tree.id)select * from tree drop table t参考: |