读书人

求从一个表更新数据到另一个表中的sql

发布时间: 2012-01-09 21:05:42 作者: rapoo

求从一个表更新数据到另一个表中的sql?
T1表:
cust model price
a b 11
a e 22

T2表:
cust model price
a b 1
a c 2

从T1表中导入数据到T2表中,如果T2表中没有T1表中的cust与model则insert,
有则update该cust与model对应的price.这样的sql怎么写比较好?
执行后得到这样的结果:
cust model price
a b 11
a c 2
a e 22

[解决办法]
--笔误
--update T2 set T2.price=T1.price from T2,T1 where T1.cust=T2.cust and T1.model=T2=model
update T2 set T2.price=T1.price from T2,T1 where T1.cust=T2.cust and T1.model=T2.model

读书人网 >SQL Server

热点推荐