[英]Invalid object name in SQL stored procedure
我已經創建為存儲過程,但是當我嘗試在ptask
中獲取數據時,出現以下錯誤
Msg 208, Level 16, State 1, Procedure mySproc, Line 72 [Batch Start Line 0]
Invalid object name 'ptask'.
我的代碼如下所示:
CREATE procedure PSBASPLG.ipMirrorFromOffer
@usr nvarchar(255),
@age int,
@id int
as
set nocount on
declare @now datetime = getdate()
exec ipLgAppend @usr, 'PSBASPLG.ipMirrorFromOffer', @pint0 = @id
;with stask (tsID, tsTag, tsNode, tsTxt, cuID, pjRef, pjRsp)
as (select top 1
ts.tsID, ts.tsTag, ts.tsNode, ts.tsTxt,
pj.pjCust, pj.pjRef, pj.pjRsp
from tbTasks as ts
inner join tbProjs as pj
on (pj.pjID = ts.tsProj)
where
(ts.tsID = @id)
)
, sleaf (lfTag, lfTxt)
as (select distinct
lf.lfTag, lf.lfTxt
from tbLeafs as lf
inner join stask as ts
on (ts.tsNode = lf.lfNode)
)
, sline (paTxt, paCnt, paSta, tyID, rsID, itID, acTyp, grID)
as (select distinct
pa.paTxt, pa.paCnt, pa.paSta, pa.paTyp, pa.paRes,
it.itID, ac.acTyp, pa.paGrp
from tbParts as pa
inner join tbActs as ac
on (pa.paAct = ac.acID)
inner join stask as ts
on (ts.tsID = ac.acTask)
inner join tbItems as it
on (it.itID = pa.paItem)
where
(pa.paStk >= 0) and
(pa.paSta > -1)
)
, ptask (tsID, tsProj, tsNode)
as (select distinct
ts.tsID, ts.tsProj, ts.tsNode
from tbTasks as ts
inner join tbLeafs as lf
on (lf.lfNode = ts.tsNode) and
(lf.lfTag = PSBASPLG.fnConf('Leaf_offertag'))
inner join stask as sl
on (sl.tsTag = lf.lfTag)
where
(ts.tsSta > -1)
)
, pline (paID, itID, acID)
as (select distinct
pa.paID, pa.paItem, ac.acID
from tbParts as pa
inner join tbActs as ac
on (pa.paAct = ac.acID)
inner join ptask as ts
on (ts.tsID = ac.acTask)
where
(pa.paStk >= 0) and
(pa.paSta > -1)
)
select * from ptask -- Error happens here
為什么ptask
是無效的 object?
您的代碼看起來有效。 如果我將您的查詢粘貼到我的編輯器中(這是標准的香草安裝),除了缺少的列和實體之外,我不會收到任何錯誤。 否則它是一個有效的查詢。
有時 VS 和 SSMS 的智能感知會損壞,特別是如果它們已經打開了很長時間。 我建議將您的查詢復制 + 粘貼到記事本中並重新啟動 SSMS。
除此之外,其中一個 CTE 中一定有錯誤。 在可能的情況下單獨運行每個應該可以揭示問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.