|
| [WD12] How to access COUNT(*) from a query |
| Iniciado por guest, 11,may. 2010 08:22 - 5 respuestas |
| |
| | | |
|
| |
| Publicado el 11,mayo 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... |
| |
| |
| | | |
|
| | |
| |
| Publicado el 11,mayo 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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 11,mayo 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) |
| |
| |
| | | |
|
| | |
| |
| Publicado el 11,mayo 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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 11,mayo 2010 - 11:52 |
Arie, Thanks for the explaination... now I understand :spos: |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 1 mensaje |
|
| Publicado el 13,junio 2017 - 07:50 |
| |
| |
| | | |
|
| | | | |
| | |
|