sql在循环中定义表变量的问题

declare @count int
set @count=4;
while(@count>0)
begin
DECLARE @STAKEHOLDERLIST TABLE (USERID UNIQUEIDENTIFIER,ID INT);
INSERT INTO @STAKEHOLDERLIST (USERID)
     EXEC [SP_GETCONSULTUSERLISTBYTASKID] 22,'83F297BF-9B03-4C3C-B949-DE849018A725'
select * from @STAKEHOLDERLIST
set @count=@count-1
end

 

declare @count int
DECLARE @STAKEHOLDERLIST TABLE (USERID UNIQUEIDENTIFIER,ID INT);
set @count=4;
while(@count>0)
begin
delete  @STAKEHOLDERLIST
INSERT INTO @STAKEHOLDERLIST (USERID)
     EXEC [SP_GETCONSULTUSERLISTBYTASKID] 22,'83F297BF-9B03-4C3C-B949-DE849018A725'
select * from @STAKEHOLDERLIST
set @count=@count-1
end

你可能感兴趣的:(sql)