Hello everyone,
I have a view containing latitude and longitude but no geography column upon which to do SQL commands. I am not able to add a column to this already existing table, so I create a temporary table and import the pertinent data.
select perno, latitude,longitude into gpstemp from avl.vwsc_DeviceLatLongHistory
where perno = 'ECSO02PER000093' and updatedatetime > '4/30/2018' and updatedatetime < '5/10/2018'
alter table gpstemp add gpsnew as geography::STGeomFromText('POINT('+convert(varchar(20),Longitude)+' '+convert(varchar(20),Latitude)+')',4326)
This all works correctly. I can query the table afterwards and see the data showing up:
But this is where I'm now unsure. I need to query this table and return all coordinates that are within 5 miles of a certain location. I set my variables, and then execute my query. But I get an error stating 'Could not find property of field 'STDistant' for type 'Microsoft.SQLServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types'.
declare @Longitude float = -87.05678
declare @Latitude float = 30.64520
declare @distance_in_meters int = 5
declare @point geography
set @point = geography::Point(@Latitude,@Longitude, 4326)
select Latitude, Longitude from gpstemp
where @point.STDistance <= @distance_in_metersc
I would greatly appreciate any assistance you could provide. Thank you so much.