0

我正在开发一个维护 SQL 数据库的项目。在这个数据库中,我有一个名为 AirportZone 的表,其属性名为“area”,类型为几何。另外,我维护了一个表 OfferRequest,其中包含一个名为“位置”的地理类型的属性。由于我想查看是否在机场区域发生了 OfferRequest,因此我想定义一个复杂的 SQL 查询,该查询将返回某个区域的用户发出的所有请求。就像是:

select OfferRequest.offer_id from OfferRequest, AirportZone 
where @tmp_geo is geography::STGeomFromText(CAST(AirportZone.area as varchar(max)), 4326)
and @tmp_geo.STIntersects(OfferRequest.location) = 1 and AirportZone.name = 'given_name'

显然这个查询是错误的,因为变量@tmp_geo(我希望它是地理类型)。有没有办法做到这一点,或者我应该定义一个while循环?

谢谢

4

1 回答 1

0

上面的查询可以实现为:

DECLARE @tmp_geo geometry;
SET @tmp_geo = geography::STGeomFromText(CAST(AirportZone.area as varchar(max));
SELECT OfferRequest.offer_id FROM OfferRequest, AirportZone WHERE
@tmp_geo.STIntersects(OfferRequest.location) = 1 AND AirportZone.name = 'given_name';
于 2012-12-20T13:50:25.213 回答