1

I want to search all records from my SQL Server database, based on some conditions
like "Near by 5 Km area", "people from my present location" (Male, Female, Both) etc.

The table structure looks like this:

Table structure

So, how can I do this?

Thanks

Vipul Odhavani
  • 127
  • 1
  • 9

2 Answers2

2

Have a read of my StackOverflow answer here:

Get the nearest longitude and latitude from MSSQL database table?

Basically, you can use the SQL Server geography type, then use STDistance.

This article includes an example, showing exactly how to use it, and also how to use Pythagorus, to calculate the distances even quicker.

Community
  • 1
  • 1
Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
0

I'm afraid you'll be force to use something like google maps API for c# to count the distance.

Otherwise, maybie you have something like additional "distance from" table, but I don't think so...
In general even if you have some table with columns like Addres, Gender it's still not that easy to perform:
Distance between addresses Solution from that answer:

public decimal calcDistance(decimal latA, decimal longA, decimal latB, decimal longB)
{

    double theDistance = (Math.Sin(DegreesToRadians(latA)) *
            Math.Sin(DegreesToRadians(latB)) +
            Math.Cos(DegreesToRadians(latA)) *
            Math.Cos(DegreesToRadians(latB)) *
            Math.Cos(DegreesToRadians(longA - longB)));

    return Convert.ToDecimal((RadiansToDegrees(Math.Acos(theDistance)))) * 69.09M * 1.6093M;
}
Community
  • 1
  • 1