2

I am studying for the SQL Server Exam one test question is:

The SpatialLocation column in the Person.Address table of the AdventureWorks2012 database uses the geography data type. You want to create a query that outputs the AddressID column with the contents of the SpatialLocation 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

4

1 回答 1

2

SpatialLocation has a Geography data type but TRY_PARSE takes a nvarchar.

TRY_PARSE ( string_value AS data_type )

Take a look here:

http://msdn.microsoft.com/en-us/library/hh213126.aspx

Good luck.

于 2013-01-31T16:28:49.897 回答