Calculating square root in ISQL
Posted in 1994
Hello
I have SE 5.01 ISQL 4.11. I do NOT have 4GL (which I understand can
do square roots.)
I need to compute the following into an sql statement.
_____________________
\\ | 2 2
\\| (x1-x2) + (y1-y2) < r1+r2
I am not sure how to do the square root part of the equation as isql does
not have this capability.
So far I have
SELECT * from file1
WHERE
((x1-field1)(x1-field1) + (y1-field2)(y1-field2)) < r1+field3
UNION
SELECT * from file1
WHERE
((x2-field1)(x2-field1) + (y2-field2)(y2-field2)) < r2+field3
UNIONetc....
(where x,y, and r are some given value)
There is a squared root option in one of the UNIX utilities:
bc
sqrt(x)
Is it possible that within isql, control can be passed to a simple shell
script, whose output is a varaible (with a value, which is a square root)
Can this variable (value) be used by isql? If so, how do I go about it ?
One idea may be somthing like this:
bc test > test1
file: test file test1
---------- ----------
sqrt(1341) 111
quit
Where you take the value of the following:
((x1-field1)(x1-field1) + (y1-field2)(y1-field2))
say it equals 1341. Put this value into a file formatted like test file
example above. Run the bc option. Put its output from test1 back
into the sql statement so that it reads:
111 < r1+field3 and sql continues on its merry way. It must do that for
each and every record.
Please send comments, suggestions, scripts to:
weller@zorro.cecer.army.mil
Many thanks
Bonnie