--你的更新方法有问题吧?--应该这样: update a set cardid=b.yid from 表1 a,表2 b where a.readerid=b.sid
--示例--示例数据 create table 表1(cardid varchar(10),readerid varchar(10)) insert 表1 select 'ty001','001' union all select 'ty002','002'create table 表2(sid varchar(10),yid varchar(10)) insert 表2 select '001','1111' union all select '002','2222' go--更新 update a set cardid=b.yid from 表1 a,表2 b where a.readerid=b.sid--显示处理结果 select * from 表1 go--删除测试 drop table 表1,表2/*--测试结果cardid readerid ---------- ---------- 1111 001 2222 002(所影响的行数为 2 行) --*/
估计你更新的时候没有设置关联条件,从而导致更新的结果是全部更新了同一个yid了
update 2 set yid=1.cardid from 1 where 2.sid=right(1.cardid,3) 或是 update 2 set yid=1.cardid from 1 where 2.sid=replace(1.cardid,'','ty')
update table1 set cardid=(select yid from table2 where table1.readerid=table2.sid)
update a set cardid=b.yid
from 表1 a,表2 b
where a.readerid=b.sid
create table 表1(cardid varchar(10),readerid varchar(10))
insert 表1 select 'ty001','001'
union all select 'ty002','002'create table 表2(sid varchar(10),yid varchar(10))
insert 表2 select '001','1111'
union all select '002','2222'
go--更新
update a set cardid=b.yid
from 表1 a,表2 b
where a.readerid=b.sid--显示处理结果
select * from 表1
go--删除测试
drop table 表1,表2/*--测试结果cardid readerid
---------- ----------
1111 001
2222 002(所影响的行数为 2 行)
--*/
或是
update 2 set yid=1.cardid from 1 where 2.sid=replace(1.cardid,'','ty')