有两个表,它们之间也有两个列相同
table1:
id, date
table2:
id, date
问题是,如何更新表2的id,它可以匹配2表中的日期,也就是说,例如。
update table2 set table2.id = table1.id Where table1.date = table2.date
感谢
答案 0 :(得分:3)
update t2 set t2.id = t1.id
from table2 t2
inner join table1 t1 on t1.date = t2.date
<强> Edit
强>
update t2 set t2.id = t1.id
from table2 t2
inner join table1 t1 on t1.date = t2.date
where convert(date,t2.date)>'2013/01/01' --YYYY/MM/DD if your Date column is datetime.