I have a table with multiple records, each contains a field called "coords". This field has been updated with a geography point.
UPDATE testing SET [coords] = geography::Point(52.029736, -113.973541, 4326)
WHERE id=2"
What I need to do is... when a user is logged in, they have a record that belongs to them, for this example says its record id #1. They need to visit a page that shows all the other records who's "coords" field is located within a certain distance.
This is the best I have come up with;
1stly, i can find the starting coordinated with this statement;
SELECT coords FROM testing WHERE id=1
This gives me the originating coordinate as coords.Lat and coords.Long
Then I would like to find ones close by, so I have this;
SELECT * FROM testing WHERE coords.STDistance() <=(20 * 1609.344)
I do not know how to put the originating coords, into that second statement to make it work.
Do I need a stored procedure, or can I somehow put the coords.Lat/ coords.Long inside the brackets of the STDistance? Or am I tottaly off base on how I'm expecting this to work.
FYI, I have very little experience with sql server, I've never done anything "advanced", only simple select * from table where record = 1
and basic inserts and updates.