Subject | Re: [IBO] Trouble with Count(*) |
---|---|
Author | Daniel Rail |
Post date | 2004-04-14T16:15:49Z |
Hi,
You need some changes in your code. See below:
At April 14, 2004, 12:14, Eric Tishler wrote:
it after ParamByName, then the Parameter value
will be resetted.
--
Best regards,
Daniel Rail
Senior System Engineer
ACCRA Group Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)
You need some changes in your code. See below:
At April 14, 2004, 12:14, Eric Tishler wrote:
> My code now looks like this:Unprepare; <- Unprepare before clear.
> 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;
> SQL.Clear;Prepare; <- Prepare before ParamByName, because if you do
> SQL.Add('SELECT COUNT(*) AS "NumStations"');
> SQL.Add(' FROM "StationInfo"');
> SQL.Add(' WHERE "SiteID" = :SiteID AND "ActivateStation" = 1');
it after ParamByName, then the Parameter value
will be resetted.
> ParamByName('SiteID').AsString := sSiteID;Hope this helps.
> // 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?
--
Best regards,
Daniel Rail
Senior System Engineer
ACCRA Group Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)