• Status: Solved
• Priority: Medium
• Security: Public
• Views: 255
• Last Modified:

# Count number of Fields in Query

Hi Experts,

Is it possible to count the number of fields in a TQuery Where the data in the field is say 'Quarterly'.

I know you can do this with a query statement, but I have several fields I want to count and only use 1 TQuery.

Thanks
Asw
0
Asw
Asked:
• 3
• 3
1 Solution

Commented:
Asw, try this:

Var iCount,
iCol: Integer;

iCount := 0;

For iCol := 0 to Query1.FieldCount DO
Begin
If Fields[0].AsString = 'Quarterly' then
Inc(iCount)
end;

Good luck with your project!
Pegasus
0

Commented:
Can you give us a little more detail on what you are doing?

Cheers,

Raymond.

0

Commented:
Asw,

Ooopppsss! The line:

For iCol := 0 to Query1.FieldCount DO

SHOULD BE:

For iCol := 0 to Query1.FieldCount-1 DO

Regards,
Pegasus
0

Author Commented:
Thanks Pegasus,

The points are yours.

Asw

0

Commented:
Your welcome Asw,

Also, another bug in my sample code, the line:

If Fields[0].AsString = 'Quarterly' then

SHOULD be:

If Fields[iCol].AsString = 'Quarterly' then

regards,
Pegasus
0

Author Commented:
Hi Pegasus,

Yesterday I quickly tried your example before going to bed
and it gave me a count of 18, I thought great without checking.

The example looks for 'Quarterly' then counts, but it does not count how many records in the TQuery contains
'Quarterly' in the payment Field, is this possible.
Example
Lets say in the query we have 10 fields containing 'Quarterly'.

Thankyou pegasus
Asw

0

Author Commented:
Hi Pegasus,

Sorry the last line should have read.

Lets say in the query we have 100 Records and only 10 where the payment field contains 'Quarterly' how do we count how many records we have containing 'Quarterly' some will have DD or Prepaid .

Asw

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 3
• 3
Tackle projects and never again get stuck behind a technical roadblock.