I am studying for the SQL Server Exam one test question is:
The
SpatialLocation
column in thePerson.Address
table of theAdventureWorks2012
database uses the geography data type. You want to create a query that outputs theAddressID
column with the contents of theSpatialLocation
column as coordinates in longitude and latitude format.
And the answer:
SELECT AddressID, CAST(SpatialLocation as VARCHAR(45)) as "LON/LAT" from Person.Address
SELECT AddressID, CONVERT(VARCHAR(45), SpatialLocation) as "LON/LAT" from Person.Address
Just playing with code why wont the following work??
TRY_PARSE( SpatialLocation AS VARCHAR(45)) as "LON/LAT3"
I get:
Invalid data type varchar in function
TRY_PARSE