Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pythagoras in a select statement

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I need to select records from a table based on a pythagorean query.
$MorcE is a fixed Easting and MorcN is a fixed Northing.
The table contains the Easting and Northing for each comparison town.
This query gives me a -2 row count (duff query) but I think it is a simple syntax problem.

Code:
SELECT REGION, COUNTY, CITY, DISTRICT FROM JADTOWN WHERE SQRT((POWER(INT($MorcE-'EAST'),2)) + (POWER(INT($MorcN-'NORT'),2))) < 50"
NB INT has to be forced to prevent negative vars.

Also, how do I order the resulting towns in distance order?

Keith
 
The problem is the useage of 'INT' which only refers to table column types. I need to convert each side of the equation to a positive integer as places to the west or south of the target will return a negative value.
I have checked out conv() as an alternative but cannot get this to play either.

Keith
 
Code:
SELECT REGION, COUNTY, CITY, DISTRICT FROM JADTOWN WHERE SQRT((POWER(242-'EAST',2)) + (POWER(463-'NORT',2))) < 50
This gives a valid query but the result of (242-'EAST') and (463-'NORT') must be forced to a positive value.

Keith
 
Getting there:-
Moving calcs to the select side and using ABS has solved the problem but how do I order the results on the calc field?
Code:
SELECT REGION, COUNTY, CITY, DISTRICT, EAST, NORT,SQRT((POWER(ABS($MorcE-EAST),2)) + (POWER(ABS($MorcN-NORT),2))) FROM JADTOWN

Keith
 
keep going, you are doing incredibly well

you've answered your own problem three times in a row

keep going

:)

r937.com | rudy.ca
 
I am still working on it, rather than allowing someone else to do my work for me but I am stumped on how to reference the calc in my query. Can I assign the calc to a var using 'select as' as I would in Foxpro, which would allow a reference to it?
Just looking for a bit of guidance.

Keith
 
It helps to discuss a problem with colleagues but thie is difficult as I work on my own. The solution, as always, was easy once I had grasped the basics.
Code:
SELECT REGION, COUNTY, CITY, DISTRICT, EAST, NORT,SQRT((POWER(ABS($MorcE-EAST),2)) + (POWER(ABS($MorcN-NORT),2))) as DIST FROM JADTOWN ORDER BY DIST LIMIT 50
Just a case of try it and see.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top