SQL Server 2008 - Get Geography From Record

Posted by user336786 on Stack Overflow See other posts from Stack Overflow or by user336786
Published on 2010-06-01T20:33:07Z Indexed on 2010/06/07 11:42 UTC
Read the original article Hit count: 222

Filed under:
|

Hello,

I am new to using the geography types in SQL Server 2008. I have a table in my database called "Location". "Location" has the following columns and types:

Location
--------
City nvarchar(256)
State nvarchar(256)
PostalCode nvarchar(25)
Latitude decimal(9, 6)
Longitude decimal(9, 6)

Each Location is related to a Store record in my database. I am trying to find the stores within a 10 mile radius or postal code or city/state that a user enters. To accomplish this, I know that I need to rely on geographies. At this time I have:

DECLARE @startingPoint geography;
SET @startingPoint=geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);

That gives me the starting point from a hard-coded textual value. However, I do not know how to convert a lat/long from my Location table into a geography instance.

How do I convert a lat/long in my database to a geography instance so I can continue to work on my query?

Thank you!

© Stack Overflow or respective owner

Related posts about sql

Related posts about geography