capdragon
capdragon

Reputation: 14899

Get X Y values from Point Geometry or Geography

I'm looking for the MSSQL equivalent of the following mySQL statement:

SELECT Y(location) as Lat, X(location) as Lon from myTable;

I want to get the X and Y values of my geography I have stored as a geography data type.

I know STAsText(Location) as Location will give me the WKT... i just need the X and Y number values.

Upvotes: 32

Views: 57486

Answers (1)

Mithrandir
Mithrandir

Reputation: 25397

For GEOGRAPHY:

SELECT location.Lat as Lat, location.Long as Lon from myTable;

For GEOMETRY:

SELECT location.STY as Lat, location.STX as Lon from myTable;

Upvotes: 65

Related Questions