我的表1带有列
我有带有列的table2
(RunID和SeqNo_In_Run)是两个表中的主键
我想在表2中添加PrimitiveID列,其中RunID和seqno_in_run与每一行都匹配。
我关注了this answer,并写了这样的内容:
Email = 'a@b.com'
但是它给了我update GPS_Snapped
set GPS_Snapped.PrimitiveID = GPS_Snapped_New.PrimitiveID
from GPS_Snapped
inner join GPS_Snapped_New
on GPS_Snapped.RunID=GPS_Snapped_New.RunID and
GPS_Snapped.SeqNo_In_Run=GPS_Snapped_New.SeqNo_In_Run
where GPS_Snapped.RunID=GPS_Snapped_New.RunID and
GPS_Snapped.SeqNo_In_Run=GPS_Snapped_New.SeqNo_In_Run
附近的错误,set GPS_Snapped.PrimitiveID
,但是我已经向GPS_Snapped添加了新列PrimitiveID,如果我执行简单的更新(例如,将更新表设置为col1 = val where condition),它就是工作正常。您能帮我解决我脚本的问题吗?
答案 0 :(得分:0)
GPS_Snapped_New
是否有Primitive_ID
列?另外,如果您已经具有join ON条件,则不需要WHERE子句。
答案 1 :(得分:0)
尝试一下:
update g
set g.PrimitiveID = n.PrimitiveID
from Table1 g
inner join Table2 n
on g.RunID = n.RunID
and g.SeqNo_In_Run = n.SeqNo_In_Run;
您无需在JOIN
上重复WHERE
条件