从另一个表更新SQL Server中的一个表的列

时间:2017-04-22 21:45:38

标签: sql-server tsql

我有一张气象站的测量表,有站名(希伯来语):

enter image description here

我还创建了一张有纬度和经度的气象站表:

enter image description here

我已经编写了一个查询,该查询应该使用第二个表中的lat / long更新第一个表,但它不起作用:

update t1
set t1.MeasurementLat = t2.Latitude,
    t1.MeasurementLong = t2.Longitude
from [dbo].[Measurements] as t1
inner join [dbo].[StationCoords] as t2 on t1.StationName like t2.Station

我认为正在读取电台名称的方式存在问题,也许与编码有关,因为此查询也会带来空结果:

SELECT TOP (5) *
FROM [dbo].[Measurements]
WHERE [StationName] = 'אריאל מכללה';

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您的示例名称不一样。也许这会奏效:

update m
    set MeasurementLat = sc.Latitude,
        MeasurementLong = sc.Longitude
    from dbo.[Measurements] m join
         dbo.[StationCoords] sc
         on m.StationName like sc.Station + '%';