0

如何清除/重置/删除循环中的临时创建表?

Another loop at the top with extra code...

How do I reset/drop the declared table up here or below?

 Declare @Aresource table(idr int identity(1,1), id int)
        Insert into @Aresource (id)
        SELECT  idr = AssignmentImageId
        FROM  VLP2014..Assignment 
                 Where AssignmentId = @ida 
        Declare @ari int
        Declare @aricnt int
        select @ari = min(idr) - 1, @aricnt = max(idr) from @Aresource
        While @ari < @aricnt
        Begin
        Select @ari = @ari + 1
        Declare @arid int
        select @arid = id from @Aresource where idr = @ari

How do I reset/drop the declared table here?
some more code...

我已经尝试过正常的 DROP TABLE(如果存在),但由于它已声明(临时表),我似乎无法调用它。

4

1 回答 1

0

修复了将普通临时表添加到数据库然后在循环后将其删除的问题。

Create Table #Aresource (idr int identity(1,1), id int)
    Insert into #Aresource (id)
    SELECT  idr = AssignmentImageId
    FROM  VLP2014..Assignment 
             Where AssignmentId = @ida 
    Declare @ari int
    Declare @aricnt int
    select @ari = min(idr) - 1, @aricnt = max(idr) from #Aresource
    While @ari < @aricnt
    Begin
    Select @ari = @ari + 1
    Declare @arid int
    select @arid = id from #Aresource where idr = @ari

...... more code ....

end
Drop table #Aresource
于 2015-02-12T18:48:07.840 回答