Subject Re: [IBO] Trouble with Count(*)
Author Daniel Rail
Hi,

You need some changes in your code. See below:

At April 14, 2004, 12:14, Eric Tishler wrote:
> 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);

> 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;
> qrySiteInfo.ExecSQL;
> Open; First;

> // loop to process each site record
> while not Eof do
> begin
> // get the SiteID
> sSiteID := FieldByName( 'SiteID' ).AsString;

> with qryStationInfo do
> begin
> // prepare query to get number of stations at current site
> Active := False;

Unprepare; <- Unprepare before clear.

> SQL.Clear;

> SQL.Add('SELECT COUNT(*) AS "NumStations"');
> SQL.Add(' FROM "StationInfo"');
> SQL.Add(' WHERE "SiteID" = :SiteID AND "ActivateStation" = 1');

Prepare; <- Prepare before ParamByName, because if you do
it after ParamByName, then the Parameter value
will be resetted.

> ParamByName('SiteID').AsString := sSiteID;

> // run the query, open the DataSet
> Execute;

> // get the number of stations at current site
> iNumStations := FieldByName('NumStations').AsInteger;

> Inspecting the value of iNumStations I get the values shown in
> the table above. Any ideas on what I am doing wrong here?

Hope this helps.

--
Best regards,
Daniel Rail
Senior System Engineer
ACCRA Group Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)