怎么更新这个表?多谢了

jamesyue2008 2012-03-13 04:09:06
a表:
Id Qty
3 150
4 160

b表
Id qty
1 100
2 300
3 Null
4 Null

怎么把a表的数据拷入b表
变b表为:
Id qty
1 100
2 300
3 150
4 160


...全文
50 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2012-03-13
  • 打赏
  • 举报
回复
update b set qty = a.qty from b , a where b.id = a.id

update b set qty = isnull((select qty from a where a.id = b.id),b.qty) from b
  • 打赏
  • 举报
回复
update b set qty=a.qty from a where a.id=b.id--更正:刚刚看错了
  • 打赏
  • 举报
回复
update b set qty=qty+a.qty from a where a.id=b.id
老猫五号 2012-03-13
  • 打赏
  • 举报
回复
update b
set b.qty = a.qty
from b inner join a on a.id = b.id
老猫五号 2012-03-13
  • 打赏
  • 举报
回复
update b
set b.qty = a.qty
from b inner join a where a.id = b.id

34,838

社区成员

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

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