sql 2000 2个不同结构表之间更新 有表A 有字段branch_no,,item_no,min_qty,max_qty,display_flag。只有item_no,min_qty,允许空。branch_no必须为00,min_qty,max_qty,display_flag有默认值。表B里有与表A只有相同字段item_no,如何通过表B里的item_no更新表A里的数据,每次更新不是全部更新,只是表A里没有表B里的这个字段数据。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 update TableASET A.需要更新字段 = B.数据字段FROM TableA A, TableB BWHERE A.item_no = B.item_no AND A.需要更新字段 is null --你想更新的内容是什么???update Aset ...where not exists(select 1from B where B.item_no=A.item_no); 只是我说的那几个字段,只要B里有的item_no,A就有,就是说B里有多少条数据,A里酒有多少。 不好意思我说错了,是表A里需要增加B里的item_no,增加数据条件只要A里没有的, 通过B里的item_no增加B里的数据条数。使A与B有同样的数据行数。 insert into 表A([字段列表])select [字段列表]from 表B bleft join 表A aon b.item_no=a.item_nowhere a.item_no is null insert into 表A(字段列表)select 字段列表from 表B aleft join 表A bon b.item_no=a.item_nowhere b.item_no is null insert into 表A([字段列表])select 字段列表 from bexcept select 字段列表 from a --orinsert into 表A(字段列表)select 字段列表from 表B a where not exists(select 1 from a where b.item_no=a.item_no) 早先的一SQL语句,如何完善它? 推荐一个网格式分布式数据库中间件给大家 关于字符型字段的序号重新排列 游标的使用问题 存儲過程變量異常提示?請各位大師兄指點:> 一个存储过程可以有多少结果集? 问一个关于update的问题 Sybase如何中实现字段自增 局域网里一台机器能访问另一台的sql server ,另一台不能访问这一台的sql server 是怎么回事? win98和winme使用SQL SERVER2000(桌面版)的全文检索功能. 问个问题:一列满足某条件时另一列必须满足另一条件的sql怎么写 sql server 查询时,表中重复项只能查询出一条数据,不重复的也查出来
SET
A.需要更新字段 = B.数据字段
FROM TableA A, TableB B
WHERE A.item_no = B.item_no AND A.需要更新字段 is null
--你想更新的内容是什么???
update A
set ...
where not exists(select 1
from B where B.item_no=A.item_no);
insert into 表A([字段列表])
select [字段列表]
from 表B b
left join 表A a
on b.item_no=a.item_no
where a.item_no is null
insert into 表A(字段列表)
select 字段列表
from 表B a
left join 表A b
on b.item_no=a.item_no
where b.item_no is null
select 字段列表 from b
except
select 字段列表 from a
select 字段列表
from 表B a where not exists(select 1 from a where b.item_no=a.item_no)