How to convert float latitude and longitude values into geography type value? I have @lat
and @lon
variables.
With case statement:
CASE
WHEN ((@Latitude IS NOT NULL) AND (@Longitude IS NOT NULL))
THEN geography::Point(@Latitude, @Longitude, 4326)
ELSE NULL
END
or a variant with if:
DECLARE @Location geography = NULL
IF (@Latitude IS NOT NULL AND @Longitude IS NOT NULL)
SET @Location = geography::Point(@Latitude, @Longitude, 4326);
I've found solution by myself:
geography::STPointFromText(
'POINT(' + CAST(@lon AS VARCHAR(20)) + ' ' + CAST(@lat AS VARCHAR(20)) + ')', 4326)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With