如何在Sql 2008中执行此空间查询?

时间:2009-01-31 05:44:25

标签: sql-server sql-server-2008 subquery spatial

我正在尝试在sql 2008中执行空间查询 - >对于给定的POI列表(兴趣点,长/纬度GEOGRAPHY数据),它们存在于(多字段GEOGRAPHY数据中)的邮政编码中。

所以这是我试过的查询,但它在语法上是不正确的: -

SELECT PostCodeId, ShapeFile
FROM Postcodes a
WHERE a.ShapeFile.STIntersects(
    SELECT PointOfInterest
    FROM PointOfInterests
    WHERE PointOfInterestId IN (SELECT Item from dbo.fnSplit(@PoiIdList, ','))

所以这意味着我传入csv list of POI Id's and split them。这不是问题..这是STIntersects中的子查询。那是无效的。

那么......有什么建议吗?

1 个答案:

答案 0 :(得分:4)

怎么样:

SELECT a.PostCodeId, a.ShapeFile
FROM (SELECT Item from dbo.fnSplit(@PoiIdList, ',')) AS POI_IDs
INNER JOIN PointOfInterests
    ON PointOfInterests.PointOfInterestId = POI_IDs.Item
INNER JOIN Postcodes a
    ON a.ShapeFile.STIntersects(PointOfInterests.PointOfInterest) = 1