Subject Re: [ib-support] For Loop
Author Helen Borrie
At 02:25 PM 27-08-01 -0500, you wrote:

>Is there a way to do some kind of loop with Ib SQL to
>keep querying records and adding them to a result set?

Yes, there is - in procedures you can loop through a SELECTed set, massage the results as required and form an output set. Look up the FOR SELECT....INTO...DO...SUSPEND construct. SUSPEND holds the set in the cache until the loop is complete. That procedure can then be SELECTed to return the massaged output.


>what I want to do is, Query for some records between a certain lat and long
>like:
>
>SELECT * FROM EXPERIAN WHERE LATITUDE BETWEEN 'xxxxxxxxx' AND 'xxxxxxxxx'
>AND
>LONGITUDE BETWEEN 'xxxxxxxxx' AND 'xxxxxxxxx'
>
>
>I I don't get enough
>
>I would like to query a second distance band and have them merged with
>the previous set ( with out having to requery first band)? may not be
>possible?

You can use a UNION query to return multiple congruent output sets in a single dataset. You could write a procedure that passes as arguments the ranges you want and apply each range to a separate UNIONed group or you can pull the dataset over using dynamic SQL.


>I tested a query like this and there was no speed degredation.
>
>SELECT * FROM EXPERIAN WHERE
> (LATITUDE BETWEEN 'xxxxxxxxx' AND 'xxxxxxxxx')
> OR
> (LATITUDE BETWEEN 'xxxxxxxxx' AND 'xxxxxxxxx')
> AND
> (LONGITUDE BETWEEN 'xxxxxxxxx' AND 'xxxxxxxxx'
> OR
> (LONGITUDE BETWEEN 'xxxxxxxxx' AND 'xxxxxxxxx')

If that returns the results you want, it seems a plausible solution.

rgds,
Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________