Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Selecting Calculated Fields and Table?

Author  Topic 

rberger
Starting Member

2 Posts

Posted - 2000-12-06 : 16:28:30
I am trying to build a SELECT query (on an active server web page) which will return all sites in our database which fall within a constant distance from a given latitude/longitude point. All site records in the table have lat/long. From the user interface, I capture target lat/long. Since this target location, I need to select all sites dynamically after performing some Pythagoream Theorem calculations to determine distance.

Here's what I'm trying to do, but it keeps failing.
"SELECT sites.name,sites.address,sites.city,sites.state,
sites.zip,sites.latitude,sites.longitude,
((UserLat-sites.latitude)^2) AS LatDistance,
((UserLong-sites.longitude)^2) AS LongDistance,
((LatDistance+LongDistance)^.5) AS HypotenuseDistance FROM sites WHERE HypotenuseDistance<10 ORDER BY HypotenuseDistance"

Can I not select by the calculated field HypotenuseDistance? If I need to nest SELECT statements, would I need to execute the first query and then run a second query which references the first query? If so, how do I say select from 'queryname'?

Many thanks,
Rob
   

- Advertisement -