SQL Query将Geography类型作为XML返回

时间:2012-03-19 18:32:42

标签: sql xml sqlgeography

我正在尝试从包含Geography类型的表中返回XML SQL查询:

SELECT *
From Events
ORDER BY HydrantId ASC
FOR XML RAW ('Event'), ROOT ('Events'), ELEMENTS XSINIL;

我收到以下错误:

FOR XML does not support CLR types -   
cast CLR types explicitly into one of the supported types in FOR XML queries.  

如何将此地理位置列转换为可读的内容? 感谢。

1 个答案:

答案 0 :(得分:3)

SELECT Column1, Column2, Column3, cast(GeographyColumn as varchar(max))
From Events
ORDER BY HydrantId ASC
FOR XML RAW ('Event'), ROOT ('Events'), ELEMENTS XSINIL;

GeographyColumn中的值将采用POINT (-77.010996 38.890358)格式。