Pergunta

I am working on a project that maintains an SQL database. In this database I have a table called AirportZone with an attribute named "area" of type geometry. Also, I maintain a table OfferRequest with an attribute named "location" of type geography. Due to the fact that I want to see if an OfferRequest occured in an Airport area, I want to define a complex SQL query that will return all the requests that were made from a user in a certain area. Something like:

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'

Obviously this query is wrong because of the variable @tmp_geo (i want it to be of type geography). Is there a way to do this, or should I define a while loop?

Thank you

Foi útil?

Solução

The above query can be implemented as:

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';
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top