declare @TempTable table(SectionID int,X int,Level int)
declare @level int
declare @TempX int
set @level=0
set @TempX=8
insert @TempTable(SectionID,X,level)
select SectionID,X,@level from spb_ForumSections where ParentID=1
while @@RowCount>0 and @tempX=8
begin
set @level=@level+1
print @level
insert @TempTable(SectionID,X,Level)
Select a.SectionID,a.X,@level
from spb_ForumSections a,@TempTable b
where a.ParentID=b.SectionID and b.level=@level-1
end
这里的循环是怎么在循环啊,可以解决下不.
declare @level int
declare @TempX int
set @level=0
set @TempX=8
insert @TempTable(SectionID,X,level)
select SectionID,X,@level from spb_ForumSections where ParentID=1
while @@RowCount>0 and @tempX=8
begin
set @level=@level+1
print @level
insert @TempTable(SectionID,X,Level)
Select a.SectionID,a.X,@level
from spb_ForumSections a,@TempTable b
where a.ParentID=b.SectionID and b.level=@level-1
end
这里的循环是怎么在循环啊,可以解决下不.
其中 @@rowcount>0 and tempx=8 是限制循环的条件
再插入表@Temptable ,直到循环不满足条件为止