子查询返回多个值,如何执行UPDATE呢?

雪月天霜 2012-06-14 10:31:55
update ST_person set is_del ='1' where person_id=(select person_id from ST_card where Card_ValidDate<getdate())

因为子查询的person_id是会有多个结果的,那我怎么样才能将 where person_id=子查询结果,这样全部update一遍呢?求指导。。我是初学者。
...全文
319 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Shawn 2012-06-14
  • 打赏
  • 举报
回复

;with cte as
(
select
a.is_del
from ST_person a
inner join ST_card b
on a.person_id = b.person_id
and b.Card_ValidDate < getdate()
)
update cte
set is_del = '1'
百年树人 2012-06-14
  • 打赏
  • 举报
回复
update a set a.is_del ='1' 
from ST_person a,ST_card b
where a.person_id=b.person_id
and b.Card_ValidDate<getdate()
黄_瓜 2012-06-14
  • 打赏
  • 举报
回复
update ST_person set is_del ='1' where person_id in (select person_id from ST_card where Card_ValidDate<getdate())
AcHerat 元老 2012-06-14
  • 打赏
  • 举报
回复

update a
set is_del ='1'
from ST_person a join ST_card b on a.person_id = b.person_id
where b.Card_ValidDate<getdate()

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧