MrBliz
MrBliz

Reputation: 5908

UPDATE SQL based on 2 conditions

Given the following table structure

Locations

LocationName|Easting|Northing

Incidents

LocationString|Easting|Northing|LocationName

LocationString is a badly formatted Subway Station Name that the user of the application can type any old rubbish in to. The eastings and Northings (Co-ordinates) are consistent however. Using them i can give the location a consistent name by looking those values up in a look up table.

In ACCESS SQL i would do the following

UPDATE INCIDENTS, Locations
SET Incidents.LocationName = Locations.LocationsName
WHERE Incidents.Easting = Locations.Easting
AND
Incidents.Northing = Locations.Northing

How do i accomplish the same in T-SQL?

Upvotes: 0

Views: 396

Answers (1)

Lamak
Lamak

Reputation: 70638

UPDATE I
SET I.LocationName = L.LocationsName
FROM Incidents I
JOIN Locations L
ON I.Easting = L.Easting AND I.Northing = L.Northing

Upvotes: 12

Related Questions