SUM /aggregated fields

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
bert herngreen
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 31.01.2007, 19:21

SUM /aggregated fields

Post by bert herngreen »

Hello,

It's probably a silly question, but how do I use an aggragate function with Zeos?

I dropped a TZQuery on a form, added a query and created an aggregated field TOTAL. After this I linked a dbgrid to a datasource, that I linked to ZQuery1. After this the 'normal' fields are visible in the dbgrid, and I would like to bind a textbox to the TOTAL. But how must I do this? The value seems to be allways empty. Next to this, if I would make a change in the SUBTOTAL field in the dbgrid, how is the TOTAL recalculated?

A piece of code from the datamodule.dfm :

Code: Select all


  object ZQuery1: TZQuery
    Connection = ZConFirebird
    BeforeScroll = ZQryVerwerkingsdatumBeforeScroll
    AfterScroll = ZQryVerwerkingsdatumAfterScroll
    OnCalcFields = ZQuery1CalcFields
    Active = True
    SQL.Strings = (
      'SELECT  * FROM batches;')
    Params = <>
    Left = 330
    Top = 368
    object ZQuery1BATCH_ID: TIntegerField
      FieldName = 'BATCH_ID'
      Required = True
    end
    object ZQuery1SUBTOTAL: TFloatField
      FieldName = 'SUBTOTAL'
    end
    object ZTOTAL: TAggregateField
      FieldName = 'TOTAL'
      Visible = True
      OnChange = ZTOTALChange
      Active = True
      currency = True
      Expression = 'sum(SUBTOTAL)'
    end
  end

Kind regards,
Bert
Post Reply