Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 8 Jahren, 2 Monaten
Letzter Beitrag:
vor 8 Jahren, 2 Monaten
Beteiligte Autoren:
DarrenF, Arie, Al

[WD12] How to access COUNT(*) from a query

Startbeitrag von DarrenF am 10.05.2010 21:39


I have what seems to be a simple question, but can't seem to get my head around how the retrieval of data works for query datasets in WD - maybe it's too late for me to be thinking :confused:

I have a simple select query that returns a count:


Then I use HExecuteQuery, but how do I retrieve the COUNT(*) value?

I'm pretty sure it's a HRead... of some kind, but what's the syntax?

Thanks in advance...


Hello Darren

I don't use queries but I use views and I can get the number of records in a view with HnbRec() Can you use that function on a query as HnbRec(QueryName) ?


von Al - am 10.05.2010 22:18
Hi Al,

Thanks for the reply...

Just tried it and the answer is "yes" it works! :cheers:

glocaliCatCount is int = HNbRec(QRY_CountActiveCategories)

glocaliProdCount is int = HNbRec(QRY_CountActiveWebProducts)

glocaliPrd2CatCount is int = HNbRec(QRY_CountProducts2Categories)

Info("Categories = " + glocaliCatCount + CR + "Products = " + glocaliProdCount + CR + "Prods 2 Cat = " + glocaliPrd2CatCount)

von DarrenF - am 10.05.2010 23:18
Darren, how do you build your query?
If you are using the designer the "count(*)" gets an alias like count_1
"select count(*) as count_1 from products"
If you build it yourself, you need to add such a field-alias as well.

Have a look at this one, just another example, returning one record with 3 fields
select SUM(amount) as total, article_id, article_description
from orders left join orderlines on orders.orderis=orderlines.orderid
where orderid={ParamOrderID}
group by article_id,article_description

Executing the query will return one record, with one or more fields field, one of them is the count or sum.
So just get the result as you would do with other queries
HReadFirst(query) // because there i just one record
nTotals is int = query.count_1
cyTotals is currency = query.total
sArticle is string = query.article_description

Notice that you will ALWAYS get one record, when grouping. Even if the table is empty. In that case your count_1=0 or total=0

von Arie - am 11.05.2010 06:34

Thanks for the explaination... now I understand :spos:

von DarrenF - am 11.05.2010 07:38
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.