SQL 存储过程 Table变量
@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)
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。