Question

I have two geospatial databases that I want to combine. One has region IDs and areas, the other has region IDs and lat/long data. The records in the area table are a subset of the records in the lat/long table.

I can do a left join to combine the areas and lat/long values. I then want to do an update to replace all the NULL areas with 0 and retrieve the resulting table.

The closest I got is:

with cte as
(select IDa, Lat, Lon, Area
from regionLL left join regionA on IDll=IDa)
update cte
set Area=0
where Area is NULL;

But the only thing displayed is "(0 row(s) affected)". I'm using sql server 2008.

Thank you for your help!

(edit 1: forgot a closing parenthesis. edit 2: fixed "ID" to "IDa")

Was it helpful?

Solution

Is this what you are looking for?

SELECT ID
    , Lat
    , Lon
    , ISNULL(Area,0)
FROM regionLL
LEFT JOIN regionA
    ON IDll = IDa

OTHER TIPS

Try this

update a
set a.Area = 0
from regionA
inner join
(
    select ID, Lat, Lon, Area
    from regionLL 
    left join regionA on IDll=IDa
) t on (a.ID = t.ID)
where t.Area is null
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top