@StatckTable table(dataValue nvarchar(50)notnull, position intnotnull)
@curPos int
@CurPos = 0
@CurPos = @CurPos + 1
into @StatckTable (dataValue,position)values(@yourValue,@CurPos)
@CurPos > 0
select @yourValue=dataValue from @StatckTable where position=@CurPosdeletefrom @StatckTable whereposition=@CurPosset @CurPos = @CurPos-1
PROCEDURE [dbo].[MyTest]
int
declare @tempTbl table(Id intNotNULL, bFound bitNotNull)declare @Count intinsertinto @tempTbl (Id,bFound)values(@Id, 0)set @Count = 1
while @Count > 0Begin
Selecttop 1 @Id = Id from @tempTbl Where bFound=0update @tempTbl set bFound=1 whereId=@Idinsertinto @tempTbl Select Id, bFound=0 from MyTreeTbl Where ParentId = @Idselect@Count=Count(*)from @tempTbl where bFound=0Endselect*from MyTreeTbl where Id in(select Id from@tempTbl)