PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → MySql - How to retrieve COUNT value
MySql - How to retrieve COUNT value
Iniciado por Gianni Spano, 14,ene. 2006 09:48 - 5 respuestas
Publicado el 14,enero 2006 - 09:48
Hello..
I'm aware this can be a stupid (or dummy) question.
Here is my little code:
//
Sql is string
Res is boolean
Sql="SELECT COUNT (*) FROM PRODUCTS"
Res=hExecuteSqlQuery (MyQuery,hquerydefault,sql)
--->>> at this point: How to retrieve the number of records??
//
Sorry, but i didn't find no examples about this...
Pls, can someone point me in the right direction?
Thanks
Gianni
Publicado el 14,enero 2006 - 19:29
Gianni
You need to send a parameter to the query and then read the record created.
This should work for you.
myQuery is Data Source
//
sql is string = "SELECT COUNT (*) as Total FROM PickLists"
Res is boolean
Total is int
//
Res=HExecuteSQLQuery(myQuery,hQueryDefault,sql)
//
HReadFirst(myQuery,Total)
WHILE NOT HOut()
//Do your stuff here
Trace(myQuery.Total)
HReadNext
END
HTH
DerekT

Hello..
I'm aware this can be a stupid (or dummy) question.
Here is my little code:
//
Sql is string
Res is boolean
Sql="SELECT COUNT (*) FROM PRODUCTS"
Res=hExecuteSqlQuery (MyQuery,hquerydefault,sql)
--->>> at this point: How to retrieve the number of records??
//
Sorry, but i didn't find no examples about this...
Pls, can someone point me in the right direction?
Thanks
Gianni
Publicado el 14,enero 2006 - 19:29
Hi Gianni...
Try with this ...
Res is boolean
MyQuery is Data Source
i is int
Res=HExecuteSQLQuery(MyQuery,"SELECT count(*) AS Count_1 FROM PRODUCTS")
HReadFirst(MyQuery)
i = MyQuery.Count_1
Info(i)
Hello..
I'm aware this can be a stupid (or dummy) question.
Here is my little code:
//
Sql is string
Res is boolean
Sql="SELECT COUNT (*) FROM PRODUCTS"
Res=hExecuteSqlQuery (MyQuery,hquerydefault,sql)
--->>> at this point: How to retrieve the number of records??
//
Sorry, but i didn't find no examples about this...
Pls, can someone point me in the right direction?
Thanks
Gianni
Publicado el 14,enero 2006 - 19:30
Hello..
Problem solved..
It was depending from the sql query..
I wrote COUNT (*) with a space between COUNT and (*).
It must be written WITHOUT any space, as COUNT(*).
Thanks
Gianni
Hello..
I'm aware this can be a stupid (or dummy) question.
Here is my little code:
//
Sql is string
Res is boolean
Sql="SELECT COUNT (*) FROM PRODUCTS"
Res=hExecuteSqlQuery (MyQuery,hquerydefault,sql)
--->>> at this point: How to retrieve the number of records??
//
Sorry, but i didn't find no examples about this...
Pls, can someone point me in the right direction?
Thanks
Gianni
Publicado el 15,enero 2006 - 21:53
Thanks for your tips, but it does not run. The "Res2" variable is always FALSE.
What i'm trying to retrieve is the number of records read from the INFORMATION_SCHEMA (a db of MySql) to retrieve the number of keys associated to the selected table, based on the 1st query.
//
Sql="SELECT * FROM KEY_COLUMN_USAGE WHERE TABLE_SCHEMA='MyTable' AND TABLE_NAME='Products'"
//
Sql2="SELECT COUNT (*) AS TOTAL FROM KEY_COLUMN_USAGE WHERE TABLE_SCHEMA='MyTable' AND TABLE_NAME='Products'"
//
Res=HExecuteSQLQuery (MyQueryKey,hQueryDefault,Sql)
>> Here the "Res" variable return TRUE and this is correct
Res2=HExecuteSQLQuery (MyQueryCount,Sql2)
Here the "Res2" variable return FALSE, and it is not correct, because there are records that should satisfy the sql query.

Where i'm in wrong?? Do i'm missing somethings?
Thanks
Gianni
Hi Gianni...
Try with this ...
Res is boolean
MyQuery is Data Source
i is int
Res=HExecuteSQLQuery(MyQuery,"SELECT count(*) AS Count_1 FROM PRODUCTS")
HReadFirst(MyQuery)
i = MyQuery.Count_1
Info(i)
Hello..
I'm aware this can be a stupid (or dummy) question.
Here is my little code:
//
Sql is string
Res is boolean
Sql="SELECT COUNT (*) FROM PRODUCTS"
Res=hExecuteSqlQuery (MyQuery,hquerydefault,sql)
--->>> at this point: How to retrieve the number of records??
//
Sorry, but i didn't find no examples about this...
Pls, can someone point me in the right direction?
Thanks
Gianni
Publicado el 15,enero 2006 - 21:53
Gianni
I am pleased you have solved your issue.
Although the actual problem did not seem to bear much in common with your orignal post.
I doubt however that the solution is to do with spaces as the query optimizer will remove all unwanted space before executing the query.
sql is string = "SELECT COUNT (*) as Total FROM PRODUCTS" will run just fine. -- Yes, I just tried it.
Regards
DerekT
Hello..
Problem solved..
It was depending from the sql query..
I wrote COUNT (*) with a space between COUNT and (*).
It must be written WITHOUT any space, as COUNT(*).
Thanks
Gianni
Hello..
I'm aware this can be a stupid (or dummy) question.
Here is my little code:
//
Sql is string
Res is boolean
Sql="SELECT COUNT (*) FROM PRODUCTS"
Res=hExecuteSqlQuery (MyQuery,hquerydefault,sql)
--->>> at this point: How to retrieve the number of records??
//
Sorry, but i didn't find no examples about this...
Pls, can someone point me in the right direction?
Thanks
Gianni