таблица времени выполнения @updated недоступна после одного использования - PullRequest
0 голосов
/ 26 мая 2020

У меня ошибка @updated.id1, поскольку она уже была объявлена ​​выше, и если я хочу, чтобы output deleted.tblId было равно @coun, то как этого добиться?

alter procedure dbo.sp_updateAndUndoQryForsubmitOrder   --  sp_updateAndUndoQryForsubmitOrder 1,1
(
    @id int,
    @for nvarchar(50)=null,
    @coun nvarchar(50)=''
)
as
begin
    DECLARE @Updated table( id1 int);
        if(@for is not null)
            begin
                update tbl_orderDetails set curStatus='depo' 
                output deleted.tblId
                into @Updated
                where id=@id
                --Update the GroupName_old with old values
                update tbl_orders
                set curstatus='Ready'
                where (
                select count(*)
                from tbl_orderDetails as a
                inner join @Updated as b
                on a.tblId=b.id1
                where a.curStatus != 'depo' or a.curStatus is null)=0 and tbl_orders.oid=@updated.id1
                update tbl_order_execution set dep_date=GETDATE() where tbl_orderDetId=@Updated.id1

            end
        else
            update tbl_orderDetails set curStatus='pro' 
            output deleted.tblId
            where id=@id 
            --Update the GroupName_old with old values
            update a
            set curStatus='0'
            from tbl_orders as a
            inner join @Updated as b
            on a.oid=b.id1;
            update tbl_order_execution set dep_date = NULL;
end

1 Ответ

0 голосов
/ 26 мая 2020

Этот запрос

update tbl_order_execution set dep_date=GETDATE() where tbl_orderDetId=@Updated.id1

имеет синтаксическую ошибку. Должно быть что-то вроде

update tbl_order_execution 
set dep_date=GETDATE() 
where tbl_orderDetId in (select id1 from @Updated)

Amd ниже

        update tbl_orderDetails set curStatus='pro' 
        output deleted.tblId
        where id=@id 

, вероятно, должно быть

        update tbl_orderDetails set curStatus='pro' 
        output deleted.tblId into @updated
        where id=@id 

Все это будет более читаемым, если вы поставите ; и пустая строка после каждого оператора.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...