Skip to main content
 首页 » 编程设计

sql-server中SQL Server 考试

2024年09月07日12lhb25

我正在准备 SQL Server 考试,测试问题是:

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.

答案:

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

祝你好运。