FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour consulta mysql y tdolphin
Posts: 84
Joined: Tue Jul 26, 2016 09:52 PM
consulta mysql y tdolphin
Posted: Thu May 17, 2018 06:01 PM

Estimados, he tratado de hacer la siguiente consulta, probe varios ejemplos de mysql, que vi o trate de adaptar y me arrojo error o me boto por error de sintaxis.. asi que llegue a esta opción,,, del tipo dbf, alguien me puede tirar una mano, de como hacer un conteo o suma de registros que cumplan cierta opcion.

cExt_Otr1:=xServer:Query("SELECT * FROM ext_otr1 WHERE fec_ing >='"+Dtos(cFecha1)+"' and fec_ing<='"+Dtos(cFecha2)+"' ORDER BY ite_rec")
cExt_Otr1:GoTop()

Do While !cExt_Otr1:EOF()
If !empty(cod_text)
cuenta++
Endif
cExt_Otr1:SKIP()
Enddo
cExt_Otr1:GoTop()

MsgInfo(Str(cuenta))

Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: consulta mysql y tdolphin
Posted: Thu May 17, 2018 07:26 PM

Quizás con count(*) si quieres contar los registros, sum( nCampoNum ) para sumar.

Saludos

Posts: 84
Joined: Tue Jul 26, 2016 09:52 PM
Re: consulta mysql y tdolphin
Posted: Thu May 17, 2018 07:44 PM

Estimado, probe esto.

Cuenta:=cExt_Otr1:=xServer:Query("SELECT COUNT(cod_text) FROM ext_otr1 WHERE fec_ing >='"+Dtos(cFecha1)+"' and fec_ing<='"+Dtos(cFecha2)+"' ORDER BY ite_rec")

MsgInfo(Str(cuenta))

probe eso y no funciono

Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: consulta mysql y tdolphin
Posted: Thu May 17, 2018 08:45 PM
Kpidata intenta asi:

Code (fw): Select all Collapse
cExt_Otr1:=xServer:Query("SELECT * FROM ext_otr1 WHERE fec_ing >='"+Dtos(cFecha1)+"' and fec_ing<='"+Dtos(cFecha2)+"' ORDER BY ite_rec")
Cuenta:=cExt_Otr1:nRecCount
?Cuenta
cExt_Otr1:GoTop()
Saludos,



Adhemar C.
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: consulta mysql y tdolphin
Posted: Thu May 17, 2018 09:50 PM
Kapidata:

Intenta con el siguiente código:

Code (fw): Select all Collapse
cExt_Otr1:=xServer:Query("SELECT *,COUNT(*) AS nNumRegs  FROM ext_otr1 WHERE fec_ing >='"+Dtos(cFecha1)+"' and fec_ing<='"+Dtos(cFecha2)+"' ORDER BY ite_rec")
cExt_Otr1:GoTop()


y en la variable nNumRegs debes obtener el número total de registros

Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: consulta mysql y tdolphin
Posted: Fri May 18, 2018 02:44 AM
Sql for counting number of records:

SELECT COUNT(*) [AS name] FROM <table> [ WHERE <condition>]
Example:
cSql := "SELECT COUNT(*) AS NumRecs FROM customer WHERE state = 'NY'"
oQry := oServer:Query( cSql )

Sql for summing fields:

SELECT SUM( <field1> ) [AS <sum1>],.. FROM <table> [WHERE <condition>]
Example:
cSql := "SELECT SUM(salary) AS TotSalary FROM customer WHERE married = 1"
oQry := oServer:Query( cSql )

For using in SQL statements, we need to convert date values to the format "'YYYY-MM-DD'"
We can largely simply our work by using Dolphin's built-in function ClipValue2SQL( <harbourvalue> )
We can also use parameters clause while opening a query

Example:
Code (fw): Select all Collapse
oQry := oServer:Query( "SELECT COUNT(*) AS NumRecs FROM ext_otr1 WHERE fec_ing BETWEEN &1 AND &2", ;
{ ClipValue2SQL( dDate1 ), ClipValue2SQL( dDate2 ) } )
Regards



G. N. Rao.

Hyderabad, India
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: consulta mysql y tdolphin
Posted: Fri May 18, 2018 03:23 PM

Mr. Rao:

Just out of curiosity, using the function DTOS() is not enough?

Regards

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: consulta mysql y tdolphin
Posted: Fri May 18, 2018 09:19 PM
Armando wrote:Mr. Rao:

Just out of curiosity, using the function DTOS() is not enough?

Regards

DTOS() is enough too.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion