我正在准备 SQL Server 考试,测试问题是:
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.
答案:
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
只是玩代码为什么下面的不起作用?
TRY_PARSE( SpatialLocation AS VARCHAR(45)) as "LON/LAT3"
我得到:
Invalid data type varchar in function
TRY_PARSE
请您参考如下方法:
SpatialLocation 具有 Geography
数据类型,但 TRY_PARSE
采用 nvarchar
。
TRY_PARSE ( string_value AS data_type )
看这里:
http://msdn.microsoft.com/en-us/library/hh213126.aspx
祝你好运。