insert into @nodes(tid)values(@nodeId)
--循环选取指定节点的子节点
while 1=1
begin
--存储表的记录数目
declare @old int
select @old=count(*) from @nodes
--循环选取表的所有子节点
insert into @nodes(tid)
select t.topicId from oaBBS_Topic t,@nodes n
where t.parentId=n.tid --子节点
and t.topicId not in --不重复
来源: