SQL存储过程临时表问题
ALTERPROCEDURE[dbo].[BalanceToXls]--Addtheparametersforthestoredprocedurehere@StartDa...
ALTER PROCEDURE [dbo].[BalanceToXls] -- Add the parameters for the stored procedure here @StartDate datetime, @EndDate datetime AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @diffdate int; declare @i int; set @i=0; set @diffdate =DATEDIFF(day,@StartDate,@EndDate) print(@diffdate); drop table ##tmp1 SELECT b.Name,a.c_date, a.[mct_Today_Payout] ,a.[mct_Today_Income] ,a.[mct_Today_Balance] into ##tmp1 FROM 表1 as a,cfg_Org_MSite as b where a.c_Userid=b.id and a.c_date=@StartDate drop table ##tmp1 while(@i<@diffdate) begin set @i=@i+1;print(@i); set @StartDate=@StartDate+@i; SELECT b.Name,a.c_date, a.[mct_Today_Payout] ,a.[mct_Today_Income] ,a.[mct_Today_Balance] into ##tmp2 FROM 表1 as a,cfg_Org_MSite as b where a.c_Userid=b.id and a.c_date=@StartDate select a.*,b.c_date, b.[mct_Today_Payout] ,b.[mct_Today_Income] ,b.[mct_Today_Balance] into ##tmp3 from ##tmp1 as a,##tmp2 as b where a.Name=b.Name drop table ##tmp1 drop table ##tmp2 select * into ##tmp4 from ##tmp3 drop table ##tmp3 end select * from ##tmp1 drop table ##tmp1 drop table ##tmp2 drop table ##tmp3 END SQL2005编译无法通过,在WHILE循环里面,我DROP了一个##TMP1,然后再往##TMP1里面写入数据,这里理论上是没问题的,可是老是提示##TMP1已经存在,所以想来请教高手了
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询