请教如何更新我的这2个表

gyl086 2019-07-10 01:34:06
aa表
bb表

我的条件是这样的
SUBSTRING(aa.TrainSerial,8,7)=bb.TrainSerial and aa.TrainIdentification='H' and bb.TrainSerial>0 and bb.yesno=0

如果符合这个条件,就把bb表的yesno改成1


请教各位老师们,看看我怎么才能实现这样的目的,谢谢啦

...全文
105 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
唐诗三百首 2019-07-10
  • 打赏
  • 举报
回复

update bb
 set yesno=1
 from bb
 inner join aa on substring(aa.TrainSerial,8,7)=bb.TrainSerial 
                  and aa.TrainIdentification='H' 
                  and bb.TrainSerial>0 
                  and bb.yesno=0
听雨停了 2019-07-10
  • 打赏
  • 举报
回复

--最好先select一下,没有问题再update
--select * 
update b set b.yesno=1
from bb as b
inner join aa as a on SUBSTRING(a.TrainSerial,8,7)=b.TrainSerial and b.TrainSerial>0
and b.yesno=0
where a.TrainIdentification='H'

34,837

社区成员

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

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