Subject Re: [IBO] Trouble with Count(*)
Author Lucas Franzen
Eric,

beside your (meanwhile solved problem) - yo oyurself a favour and make
it easier for yourself:


> My code now looks like this:
>
> var
> sSiteID : string;
> iNumStations : integer;
> qrySiteInfo : TIBOQuery;
> qryStationInfo : TIB_DSQL;
> begin
> // create the query objects
> qrySiteInfo := TIBOQuery.Create(Application);
> qryStationInfo := TIB_DSQL.Create(Application);

aren't they bound to any Database Component?

>
> with qrySiteInfo do
> begin
> // prepare the query to get each site name
> Active := False;
> SQL.Clear;
> SQL.Add('SELECT "SiteID" from "GeneralOptions"');
>
> // run the query, open the DataSet
> qrySiteInfo.Prepare;

you prepare the statement. ok

> qrySiteInfo.ExecSQL;

Now you execute a SELECT????

> Open;

After that your're opening it.

First;

Now you're setting it to First (what for? Where do you expect the
dataset to be at?)

Now you're stepping through all your records, prepare and execute a
second query to get the count for every detail.

Have you ever considered sth. like:

SELECT G.SiteID, Count (*) as NumStations
from GeneralOptions G
JOIN StationInfo S on G.SiteId = S.SIteID
GROUP BY G.SiteID


Let the server do the counting job, if it really has to be done (as
Helen said).

Luc.