简体   繁体   English

如何删除SQL Server存储过程中使用的@Temp表

[英]How to drop the @Temp table used in SQL Server stored procedure

I am using cursor to pass the each employee wise information to do some calculation inside, 我正在使用游标传递每个员工的明智信息在内部进行一些计算,

I have used some temp table with the declaration like 我已经使用了一些临时表,像这样的声明

declare @tempTask1 table(emplid nvarchar(10), Values bigint)

and storing it into the main table 并将其存储到主表中

insert into Maintable
Select * from @tempTask1 

but what happens is when the loop goes the emplid is kept on adding into the @tempTask1 . 但是发生的是,当循环结束时,将emplid继续添加到@tempTask1

like example 像例子

E1 1001
E2 1002
...

as per the no of times the loop goes 根据循环的次数

so duplicate entry exists for each record and calculation failed. 因此,每个记录都有重复的条目,并且计算失败。

How to drop this temp table and recreate the emp table used inside the loop to avoid these data problems. 如何删除此临时表并重新创建循环内使用的emp表,以避免出现这些数据问题。

Note: each loop shld take only unique emplid one time when it loops 注意:每个循环在循环时仅占用唯一的一次

您可以使用删除语句

DELETE @tempTask1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM