consulta mysql y tdolphin

consulta mysql y tdolphin

Postby kpidata » Thu May 17, 2018 6: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))
kpidata
 
Posts: 80
Joined: Tue Jul 26, 2016 9:52 pm

Re: consulta mysql y tdolphin

Postby horacio » Thu May 17, 2018 7:26 pm

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

Saludos
horacio
 
Posts: 1362
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: consulta mysql y tdolphin

Postby kpidata » Thu May 17, 2018 7: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
kpidata
 
Posts: 80
Joined: Tue Jul 26, 2016 9:52 pm

Re: consulta mysql y tdolphin

Postby acuellar » Thu May 17, 2018 8:45 pm

Kpidata intenta asi:

Code: Select all  Expand view

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.
User avatar
acuellar
 
Posts: 1630
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: consulta mysql y tdolphin

Postby Armando » Thu May 17, 2018 9:50 pm

Kapidata:

Intenta con el siguiente código:

Code: Select all  Expand view

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
User avatar
Armando
 
Posts: 3177
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: consulta mysql y tdolphin

Postby nageswaragunupudi » Fri May 18, 2018 2: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: Select all  Expand view

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
User avatar
nageswaragunupudi
 
Posts: 10468
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: consulta mysql y tdolphin

Postby Armando » Fri May 18, 2018 3: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
User avatar
Armando
 
Posts: 3177
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: consulta mysql y tdolphin

Postby nageswaragunupudi » Fri May 18, 2018 9: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
User avatar
nageswaragunupudi
 
Posts: 10468
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 27 guests