Error updating sql server geography type in trigger
-
30-10-2019 - |
Question
I have the following trigger in my database:
CREATE TRIGGER dbo.triggerGeocodedAddressUpdate ON dbo.Party AFTER UPDATE AS
IF UPDATE(Latitude)
UPDATE pt
SET pt.GeocodedAddress = geography::Point(i.Latitude, i.Longitude, 4326)
FROM dbo.Party AS pt INNER JOIN inserted AS i ON i.PartyId = pt.PartyId
WHERE (i.Latitude IS NOT NULL AND i.Longitude IS NOT NULL);
RETURN
IF UPDATE(Longitude)
UPDATE pt
SET pt.GeocodedAddress = geography::Point(i.Latitude, i.Longitude, 4326)
FROM dbo.Party AS pt INNER JOIN inserted AS i ON i.PartyId = pt.PartyId
WHERE (i.Latitude IS NOT NULL AND i.Longitude IS NOT NULL);
RETURN
GO
But every time I try to update a row in the Party table, I get an error, even if I don't change the Latitude or Longitude fields.
The error is:
geography::Point' failed because parameter 1 is not allowed to be null.
Any ideas? I'm pretty new to triggers, so I'm sorry if it's something simple and obvious.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange