求一条sql语句

qozm 2004-03-19 12:07:47
假设我有表A
id user_code user_name
1 a001 null
2 a002 null
3 a003 null
……

另外有一个其他系统的表B如下:
user_code user_name
a001 张三
a002 李四
a003 王五
……



我要用一条sql语句将B表中的名字字段写到A表的user_name字段中去,该怎么写sql语句?
...全文
97 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
erlengzi2003 2004-03-19
  • 打赏
  • 举报
回复
可以编制一个存储过程

利用循环控制语句,和指针,将符合条件的值逐个地进行更新
kingxx 2004-03-19
  • 打赏
  • 举报
回复
select A.id,A.user_code,B.user_name
from A,B
where A.user_code*=B.user_code
这样不就行了吗??^-^
不过你的A表最好加点约束条件好点。
maimaizhi 2004-03-19
  • 打赏
  • 举报
回复
update A set user_name=t2.user_name from 表A as t1,表B t2 where t1.user_code=t2.user_code
shuichangliu 2004-03-19
  • 打赏
  • 举报
回复
update a set a.user_name=b.user_name from 表A a,表B b where a.user_code=b.user_code
poormsteven 2004-03-19
  • 打赏
  • 举报
回复
update 表A set 表A.user_name=表B.user_name from 表A inner join 表B on 表A.user_code=表A.user_code
zheninchangjiang 2004-03-19
  • 打赏
  • 举报
回复
update a set a.user_name=b.user_name from 表A a,表B b where a.user_code=b.user_code
eastasp 2004-03-19
  • 打赏
  • 举报
回复
上面全对,该姐贴了

34,873

社区成员

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

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