繁体   English   中英

存储过程中定义的临时表的对象名称无效错误

[英]Invalid object name error for temporary table defined in a stored procedure

我编写了一个存储过程,它执行一个存储过程,它得到的结果必须存储在本地临时表中。 创建存储过程时不会出现任何错误。 但是当我尝试执行存储过程时,它返回临时表是无效对象名称的错误。

CREATE PROCEDURE .dbo.CalulateETFWeights
-- Add the parameters for the stored procedure here
@CURR_DATE varchar(255),
@ETF_DATE datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

--Select max(ETF_DATE) into @ETF_DATE from .dbo.ETF_LIST_V --where ETF_LOAD_DATE = @CURR_DATE

-- Insert statements for procedure here
SELECT TqaSecCode, GlobalSecurity, Cusip
into #tempetftable
from .map.v_get_tqa_security where cusip in (select distinct ETF_CUSIP from .dbo.ETF_LIST_V where ETF_LOAD_DATE = 'Mon Jun 17 14:15:09 BST 2019')


Insert into #tempPriceTable
exec .tqaif.sp_get_ds_price_usd
    @sourceTable = '#tempetftable',
    @startDate = '20181219',
    @endDate = '20181219',
    @frequency = 'D'


Insert into .dbo.ETFComponentWeights

Select 
    C.ETF_CUSIP as W_CAL_CUSIP,
    C.STK_IDX as W_CAL_COMP,
    C.STK_QUANT as W_CAL_SHARES,
    CP.VALUE as W_CAL_PRICE,
    (C.STK_QUANT  * CP.VALUE_) as W_CAL_MVAL,
    (C.STK_QUANT * CP.VALUE_)/SUM(C.STK_QUANT * CP.VALUE) over (partition by C.ETF_CUSIP) as W_CAL_WEIGHT,
    @ETF_DATE as W_CAL_DATE

from .dbo.ETF_COMP_V C
    inner join (Select E.CUSIP, P.Value_ from #tempPriceTable P inner join #tempetftable E on P.TqaSecCode = E.TqaSecCode) CP
    on C.ETF_CUSIP = CP.CUSIP

所以我得到的错误是 Invalid object name '#tempPriceTable'。

我不明白为什么这不起作用? 谁能建议我在这里做错了什么? 以及为什么#tempetftable 工作正常。 但是这里的#tempPriceTable 在这种情况下不起作用?

句法:

SELECT TqaSecCode, GlobalSecurity, Cusip
into #tempetftable

创建一个新的临时表,然后将数据插入到这个新表中。

句法:

Insert into #tempPriceTable
exec .tqaif.sp_get_ds_price_usd

是一个常规的“插入”语句,它将行添加到现有表中。 要使用此语法,您需要事先创建一个具有正确架构的空临时表。 因此,您需要执行以下操作:

CREATE TABLE #tempPriceTable (your schema)
Insert into #tempPriceTable
exec .tqaif.sp_get_ds_price_usd

暂无
暂无

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

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