sql update table set - The multi-part identifier could not be bound

前端 未结 2 1025
傲寒
傲寒 2021-01-05 02:18

I have 2 tables:

  • Table1 = names of gas stations (in pairs)
  • Table2 = has co-ordinate information (longitude and latit
相关标签:
2条回答
  • 2021-01-05 02:46

    You need to change the inner table and give a different allias to the columns that are similar. This should work.

    update table1
    set [Lattitude1] = x.[lat]
    from 
    (
        SELECT IDInfo [id], Lattitude [lat] FROM 
        table2
    ) x
    WHERE
    StationID1 = x.[id]
    

    In your particular case its not necessary to rename Lattitude to lat, but if you end up updating a table with itself and force yourself into giving the columns different names, it will save you headaches down the road.

    0 讨论(0)
  • 2021-01-05 02:59

    I think you can modify your UPDATE statement to reference the table alias in the UPDATE line.

    update t1
    set t1.[Lattitude1] = t2.[Lattitude]
    from table1 t1
    left join table2 t2 
    on (t1.StationID1 = t2.IDInfo)
    
    0 讨论(0)
提交回复
热议问题