Board index » delphi » Assign var result from Query

Assign var result from Query

If I run a query called qryGetTot e.g. SELECT sum(InstAmount) FROM debt
how can I assign the result to a variable e.g.  myVar := ??????
 Thanks for any help,

Chris

ChrisRoss....@EggConnect.net

 

Re:Assign var result from Query


 have tried
MyVar := qryGetTot.FieldByName('xyz').asFloat;

but this always comes back as zero ?

Quote
chrisross.arc <chrisross....@eggconnect.net> wrote in message

news:39edac88$1_1@dnews...
Quote
> If I run a query called qryGetTot e.g. SELECT sum(InstAmount) FROM debt
> how can I assign the result to a variable e.g.  myVar := ??????
>  Thanks for any help,

> Chris

> ChrisRoss....@EggConnect.net

Re:Assign var result from Query


var
  InstAmount:  Currency;
begin
  qryGetTot.Open;
  InstAmount := qryGetTot.Fields[0].AsCurrency;

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Assign var result from Query


Quote
chrisross.arc wrote in message <39eddfbd_2@dnews>...
> have tried
>MyVar := qryGetTot.FieldByName('xyz').asFloat;

>but this always comes back as zero ?

Because there's no such field as 'xyz'. The easiest way is as Bill has
already shown, but you could also name your field in the query like so:
    SELECT sum(InstAmount) as Total FROM debt

Then FieldByName can also work:

    MyVar := qryGetTot.FieldByName('Total').asFloat;

--
Wayne Niddery (WinWright Inc.)
RADBooks - http://members.home.net/wniddery/
I love deadlines. I like the whooshing sound they make as they pass by -
Douglas Adams

Other Threads