2012-07-04 2 views
0

SQL 데이터베이스를 유지 관리하는 프로젝트에서 작업하고 있습니다. 이 데이터베이스에는 "area"라는 이름의 특성이있는 AirportZone이라는 테이블이 있습니다. 또한 필자는 geography 유형의 "location"이라는 특성을 가진 테이블 OfferRequest를 유지 관리합니다. OfferRequest가 Airport 영역에서 발생했는지 확인하고 싶기 때문에 특정 영역의 사용자로부터 요청 된 모든 요청을 반환하는 복잡한 SQL 쿼리를 정의하려고합니다. 같은 뭔가 :SQL Server 2008 공간 데이터 선택 쿼리

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 루프를 정의해야합니까?

감사합니다

답변

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';