sql - 使用一次后无法访问运行时表 @updated
问题描述
我有一个错误,@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
解决方案
这个查询
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
;
如果您在每条语句后加上一个空行,这一切都将更具可读性。
推荐阅读
- javascript - 为什么我的字幕显示为未定义?
- reactjs - 反应数组循环不生成 HTML
- c - 您如何构建 Pion mediadevices webrtc 示例?
- c# - 仅在最终迭代 c# 上运行的协程
- c# - 在 Unity 的公共静态 void 中启动协程?
- jenkins - 从 Jenkins 触发时,Mozilla Sops 无法解密
- javascript - 电子从具有偏移量和长度的路径读取文件
- antlr4 - 如何允许特殊字符,例如 * 或 ? 在 Antlr 中的令牌中
- python-3.x - 访问同一类python中的局部变量
- regex - 在文本文件中查找正则表达式模式并将每个匹配项输出到新文本文件