Неверное имя объекта в хранимой процедуре SQL - PullRequest
0 голосов
/ 16 октября 2019

Я создал как хранимую процедуру, но когда я пытаюсь получить данные в 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 недопустимый объект?

...