当前位置: 代码迷 >> Sql Server >> 求SQL语句,比较简单!该怎么解决
  详细解决方案

求SQL语句,比较简单!该怎么解决

热度:405   发布时间:2016-04-27 21:16:22.0
求SQL语句,比较简单!
表A:

name    
dept

表B:

name
dept

我想用一条update语句修改掉所有表B的dept,从表A里查到,name字段相互对应!

------解决方案--------------------
update b
set dept=a.dept
from 表A a inner join 表b b
on a.name=b.name
------解决方案--------------------
update b
set dept = a.dept
from b,a
where b.name = a.name
------解决方案--------------------
update b
set dept=a.dept
from 表A a inner join 表b b
on a.name=b.name

------解决方案--------------------
update b set dept = a.dept from tab1 as a inner join tab2 as b
on (a.name = b.name)
------解决方案--------------------
update b set dept = a.dept from (select * from tab1 as a inner join tab2 as b
on a.name = b.name)

------解决方案--------------------
你倆表的dept 的數據類型是啥?

試下這個

Update B Set dept = Left((Select dept From A Where name = B.name), 8000)
------解决方案--------------------
楼主把varchar改为text试试!