FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV 2024
→
[WD12] How to access COUNT(*) from a query
[WD12] How to access COUNT(*) from a query
Débuté par DarrenF, 11 mai 2010 08:22 - 5 réponses
Connectez-vous…
DarrenF
#1
Posté le 11 mai 2010 - 08:22
Hi,
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:
SELECT COUNT(*) FROM PRODUCTS;
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...
Signaler
0
0
Al
#2
Posté le 11 mai 2010 - 08:23
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) ?
Regards
Al
Signaler
0
0
DarrenF
#3
Posté le 11 mai 2010 - 08:23
Hi Al,
Thanks for the reply...
Just tried it and the answer is "yes" it works! :cheers:
HExecuteQuery
(
QRY_
CountActiveCategories
)
glocaliCatCount is
int
=
HNbRec
(
QRY_
CountActiveCategories
)
HExecuteQuery
(
QRY_
CountActiveWebProducts
)
glocaliProdCount is
int
=
HNbRec
(
QRY_
CountActiveWebProducts
)
HExecuteQuery
(
QRY_
CountProducts2Categories
)
glocaliPrd2CatCount is
int
=
HNbRec
(
QRY_
CountProducts2Categories
)
Info
(
"Categories = "
+
glocaliCatCount
+
CR
+
"Products = "
+
glocaliProdCount
+
CR
+
"Prods 2 Cat = "
+
glocaliPrd2CatCount
)
Signaler
0
0
Arie Mars
#4
Posté le 11 mai 2010 - 11:03
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
or
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
Signaler
0
0
DarrenF
#5
Posté le 11 mai 2010 - 11:52
Arie,
Thanks for the explaination... now I understand :spos:
Signaler
0
0
sandra louis
#6
Membre enregistré
1 message
Posté le 13 juin 2017 - 07:50
Queries are helpful way of extracting information from one or more tables based on a set of search condition given by you. This tutorial help you in acquiring the complete knowledge on query, how to design and run the query wizard in MS Access. Learn how it is to be done.
Read more:
http://repairmsaccess.weebly.com/blogs/how-to-run-the-query-wizard-in-access
Signaler
0
0
→ Revenir à WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte