寻求判断编码是否相同然后更新价格的代码
数据库有两个表,表1和表2,结构如下
表1
bianma jiage
111AADDD111
222ffg21
3434ffggg34
表2
PartsnumPartspri
111AADDD
122dfdf
2d232323
我想用表1的“bianma”与表2“partsnum”进行比对,如果有相同则用表1的“jiage”替换表2的“partspri”。寻求这样的SQL语句,多谢各位朋友,帮帮忙了。
[解决办法]
update B set b.partspri=a.jiage from A JOIN B ON a.bianma=b.partsnum
[解决办法]
update 表2set partspri =表1.jiagefrom 表1where 表1.bianma = 表2.partsnum
[解决办法]
create table #a (bianma varchar(20),jiage int )create table #b(Partsnum varchar(20),Partspri int)--drop table #b--drop table #ainsert into #a select '111AADDD',111 UNION ALLselect '222ffg',21 UNION ALLselect '3434ffggg',34insert into #b select '111AADDD',0 UNION ALLselect '1222dfdf',0 UNION ALLselect '2d232323',0select * from #aselect * from #bupdate b set b.Partspri=a.jiage from #a a,#b b where a.bianma=b.partsnum--结果:Partsnum Partspri111AADDD 1111222dfdf 02d232323 0