Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count number of Fields in Query

Posted on 1999-07-22
7
Medium Priority
?
241 Views
Last Modified: 2010-04-04
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
Comment
Question by:Asw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 200 total points
ID: 1390537
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1390538
Can you give us a little more detail on what you are doing?

Cheers,

Raymond.

0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1390539
Asw,

  Ooopppsss! The line:

For iCol := 0 to Query1.FieldCount DO

SHOULD BE:

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

Regards,
Pegasus
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Asw
ID: 1390540
Thanks Pegasus,

The points are yours.

Asw

0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1390541
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
 
LVL 1

Author Comment

by:Asw
ID: 1390542
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
 
LVL 1

Author Comment

by:Asw
ID: 1390543
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question