I am studying for the SQL Server Exam one test question is:
The
SpatialLocationcolumn in thePerson.Addresstable of theAdventureWorks2012database uses the geography data type. You want to create a query that outputs theAddressIDcolumn with the contents of theSpatialLocationcolumn 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