Well, I have an Android app that uses Google Maps API. On the map, I get data from a SQL Server database. I need to create a radius in KM in which I just load the data from the bank that are within this radius. This is based on the current geolocation of the user's device.
I used MySQL, in it I could do this using this formula:
SELECT DISTINCT filiais.icon_logo_maps,
filiais.latitude_fil,
filiais.longitude_fil,
filiais.nr_cnpj_filial,
(6371 acos(cos(radians(latitude_dispositivo))cos(radians(filiais.latitude_fil))cos(radians(longitude_dispositivo) - radians(filiais.longitude_fil))sin(radians(latitude_dispositivo))sin(radians(filiais.latitude_fil)) AS distance
FROM _using.produto
INNER JOIN _using.filiais ON _using.produto.cnpj_filial = _using.filiais.nr_cnpj_filial
WHERE _using.produto.subcat = 'mercad'
HAVING distance <= 7;
How could I use this same formula for SQL Server?
In SQL SERVER I encounter the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: Column Name 'distance' is invalid.