存储过程查询结果如何赋值给变量?
寂灭我有 2019-08-16 02:34:19 我需要根据子查询条件得到其结果,对A,B两张表进行更新,但是如果我先对A表(子查询也是A表)更新了,查询结果就变了,此时对B表更新条件就不正确。如下所示:
先对表A进行更新,
update A set A.Status = 2 where A.Id in
(
select id from (select t.id from A as t where t.Status = 1)as t
)
然后对表B进行更新
update B set B.Name= "test" where B.Id in
(
select id from (select t.id from A as t where t.Status = 1)as t //此时表A的Status不在是1了,状态变更了
)
是否有方法可以把select id from (select t.id from A as t where t.Status = 1)as t 这个的结果赋值到临时变量,然后在进行表A和B的操作,谢谢!