I have a view that contains two fields for latitude and longitude, and I would like to create a new view that converts these lat/lon fields into a geometry/geography field (
Juan's answer put me on the right track. When dealing with Geometry I initially used
geometry::Point([Latitude], [Longitude], 4326) as Geom
But when I tried to access the longitude with Geom.STX it would return the latitude value. And Geom.STY would actually return the longitude value.
I had to use
geometry::Point([Longitude], [Latitude], 4326) as Geom
Just wanted to provide this for anyone else that runs into some issues involving the geometry type.
SELECT *,
geography::STGeomFromText('POINT(' +
CAST([Longitude] AS VARCHAR(20)) + ' ' +
CAST([Latitude] AS VARCHAR(20)) + ')', 4326) as GEOM,
geography::Point([Latitude], [Longitude], 4326) as SAME_GEOM
FROM view_name
WHERE (latitude <> 0) AND (longitude <> 0)