I'm new in MSSQL server, I've changed my db from postgres to mssql server 2013. Prior I have used raw query in my Django(python) application and after changing my db to mssql, the buit in function of postgres does not exits in mssql sevrer. So is there any buitin function in mssql server similar to ll_to_earth and earth_distance.
My GenericViewSet in django, in which I have added raw query with ORM
def list(self, request):
'''docstring'''
params = request.data
distance_range = params['range'] * 1609.34 if 'range' in params and params['range'] else 2 * 1609.34
queryset = ValetAt.objects.raw('''
SELECT valetat.id, earth_distance(ll_to_earth({},{}), ll_to_earth(valetat.latitude, valetat.longitude)) as distance FROM valetat WHERE earth_box(ll_to_earth({},{}),{}) @> ll_to_earth(valetat.latitude, valetat.longitude) ORDER BY distance ASC;
'''.format(params["latitude"], params["longitude"], params["latitude"], params["longitude"], distance_range))
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)