我正在尝试从不同的表中选择值并将其插入到临时表中。
我需要在临时表中使用一个标识字段。当我尝试执行以下代码时,它会抛出错误:
*Msg 2714, Level 16, State 1, Procedure SelectCashDetails, Line 27
There is already an object named '#ivmy_cash_temp1' in the database.*
即使我将临时表更改为不同的名称,它仍然会抛出相同的错误。
这是我的代码:
我需要在临时表中使用一个标识字段。当我尝试执行以下代码时,它会抛出错误:
*Msg 2714, Level 16, State 1, Procedure SelectCashDetails, Line 27
There is already an object named '#ivmy_cash_temp1' in the database.*
即使我将临时表更改为不同的名称,它仍然会抛出相同的错误。
这是我的代码:
ALTER PROCEDURE [dbo].[SelectCashDetails]
(
@trustcompanyid BigInt,
@trustaccountid BigInt,
@planid BigInt,
@fromdate varchar(20),
@todate varchar(20),
@movetype varchar(20),
@typedesc varchar(20)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
CREATE TABLE #ivmy_cash_temp1
( tmovedate datetime,
tmovedesc varchar(20),
tmoneymovetype varchar(20),
tplanbal decimal(18,6),
tsourcetype BigInt,
tdestinationtype BigInt)
SELECT
IDENTITY(int) AS id,
CMM.movedate,
CDCP.paramdesc,
CMM.movementtypecd,
CMM.amountmoved,
CMM.planbalance,
cmm.sourceaccounttypeid,
cmm.destinationaccounttypeid
into #ivmy_cash_temp1
from
cash_moneymove CMM
inner join
CDC_PARAMETERS CDCP on CMM.movedescriptioncd=CDCP.paramcd
where
CMM.movedescriptioncd = @typedesc
and PARAMNAME = 'Cash AccountType Desc'
select * from #ivmy_cash_temp1
END