Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problema con consulta (Extraño) (https://www.clubdelphi.com/foros/showthread.php?t=40947)

Caral 02-03-2007 22:43:09

Hola
Opcion jhonny:
Código Delphi [-]
ADOQuery1.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
Opcion vtdeleon:
Código Delphi [-]
ADOQuery1.Parameters.ParamByName('fecha').value := StrToDate(DateToStr(DTP1.Date)); 
    ADOQuery1.Parameters.ParamByName('fecha').DataType:=ftDate ;
La dos funcionan igual.
Muchas gracias por estar ayudandome.
Saludos

vtdeleon 02-03-2007 22:47:01

StrToDate(DateToStr(DTP1.Date))
No creo que sea necesario hacer todas esas conversiones, con solo poner DTP1.date, debería bastar.

Caral 02-03-2007 22:54:40

Hola vtdeleon
Gracias por estar ayudandome;
No vasta, me da un error dice que no coinciden los tipos, si pongo todo eso si funciona bien.
Saludos

Caral 02-03-2007 23:08:04

Hola
Muchisimas Gracias a todos, ya lo solucione, con la opcion de jhonny modificada, ya me da todos los datos.
Nota: La opcion de vtdeleon funciona a la perfecion tambien.
Sois unos verdaderos Maestros.
Muchas Gracias de nuevo y que paseis un buen fin de semana.
Saludos

jhonny 02-03-2007 23:11:38

Me alegra que todo vaya bien :) , Pero me da curiosidad y seria bueno que nos mostraras cómo quedo finalmente la cosa ;).

roman 02-03-2007 23:14:06

Yo también quiero verlo. La verdad es que la opción de Van Troi fue lo que intenté pero intercambiando el orden: primero el DataType y luego la sustitución, y simplemente no me encuentra ningún registro.

// Saludos

Caral 02-03-2007 23:18:43

Hola
Gracias jhonny
Asi Quedo:
Código Delphi [-]
procedure TFReporteDiario.DTP1Change(Sender: TObject);
begin
   ADOQuery1.Active:= False;
   ADOQuery1.SQL.Text:= 'SELECT DISTINCTROW Factura.Fecha, Factura.Terminos, Sum(Factura.MntTotal) AS SumaDeMntTotal '+
                        ' FROM Factura '+
                        ' WHERE Factura.Fecha = :Fecha AND Factura.Terminos = "Contado" '+
                        ' GROUP BY Factura.Fecha, Factura.Terminos ';
    ADOQuery1.Active:= True;
    ADOQuery1.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   // esta opcion tambien sirve
  //  ADOQuery1.Parameters.ParamByName('fecha').value := StrToDate(DateToStr(DTP1.Date));
  //  ADOQuery1.Parameters.ParamByName('fecha').DataType:=ftDate ;
    ADOQuery2.Active:= False;
   ADOQuery2.SQL.Text:= 'SELECT DISTINCTROW Factura.Fecha, Factura.Terminos, Sum(Factura.MntTotal) AS SumaDeMntTotal '+
                        ' FROM Factura '+
                        ' WHERE Factura.Fecha = :Fecha AND Factura.Terminos = "Credito" '+
                        ' GROUP BY Factura.Fecha, Factura.Terminos ';
    ADOQuery2.Active:= True;
    ADOQuery2.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

   ADOQuery3.Active:= False;
   ADOQuery3.SQL.Text:= 'SELECT DISTINCTROW PagosAdelanto.FechaTransac, Sum(PagosAdelanto.MontoCompra) AS [Suma De MontoCompra], Sum(PagosAdelanto.Abono) AS [Suma De Abono] '+
                        ' FROM PagosAdelanto'+
                        ' WHERE PagosAdelanto.FechaTransac = :FechaTransac'+
                        ' GROUP BY PagosAdelanto.FechaTransac ';
    ADOQuery3.Active:= True;
    ADOQuery3.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

    ADOQuery4.Active:= False;
   ADOQuery4.SQL.Text:= 'SELECT DISTINCTROW BancoNac.FechaTransac, Sum(BancoNac.Retiros) AS [Suma De Retiros], Sum(BancoNac.Depositos) AS [Suma De Depositos] '+
                        ' FROM BancoNac'+
                        ' WHERE BancoNac.FechaTransac = :FechaTransac'+
                        ' GROUP BY BancoNac.FechaTransac ';
    ADOQuery4.Active:= True;
    ADOQuery4.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

    ADOQuery5.Active:= False;
   ADOQuery5.SQL.Text:= 'SELECT DISTINCTROW BancoSanJoseco.FechaTransac, Sum(BancoSanJoseco.Retiros) AS [Suma De Retiros], Sum(BancoSanJoseco.Depositos) AS [Suma De Depositos] '+
                        'FROM BancoSanJoseco'+
                        ' WHERE BancoSanJoseco.FechaTransac = :FechaTransac'+
                        ' GROUP BY BancoSanJoseco.FechaTransac ';
    ADOQuery5.Active:= True;
    ADOQuery5.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

    ADOQuery6.Active:= False;
   ADOQuery6.SQL.Text:= 'SELECT DISTINCTROW BancoSanJosedol.FechaTransac, Sum(BancoSanJosedol.Retiros) AS [Suma De Retiros], Sum(BancoSanJosedol.Depositos) AS [Suma De Depositos] '+
                        ' FROM BancoSanJosedol'+
                        ' WHERE BancoSanJosedol.FechaTransac = :FechaTransac'+
                        ' GROUP BY BancoSanJosedol.FechaTransac ';
    ADOQuery6.Active:= True;
    ADOQuery6.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

   ADOQuery7.Active:= False;
   ADOQuery7.SQL.Text:= 'SELECT DISTINCTROW CxPDetalle.FechaPago, CxPDetalle.TipoTransac, Sum(CxPDetalle.Monto) AS [Suma De Monto] '+
                        ' FROM CxPDetalle'+
                        ' WHERE CxPDetalle.FechaPago = :FechaPago AND CxPDetalle.TipoTransac ="PA" '+
                        ' GROUP BY CxPDetalle.FechaPago, CxPDetalle.TipoTransac';
    ADOQuery7.Active:= True;
     ADOQuery7.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

      ADOQuery8.Active:= False;
   ADOQuery8.SQL.Text:= 'SELECT DISTINCTROW CxCDetalle.FechaCobro, CxCDetalle.TipoTransac, Sum(CxCDetalle.Monto) AS [Suma De Monto] '+
                        ' FROM CxCDetalle'+
                        ' WHERE CxCDetalle.FechaCobro = :FechaCobro AND CxCDetalle.TipoTransac ="PA" '+
                        ' GROUP BY CxCDetalle.FechaCobro, CxCDetalle.TipoTransac';
    ADOQuery8.Active:= True;
    ADOQuery8.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

end;
Si no se ve bien, por favor arreglenlo.
Roman, jhonny, vtdeleon, delphi.com.ar y todos muchas gracias
Saludos

jhonny 02-03-2007 23:29:28

Si le quitamos unas cuantas lineas al principio también te funcionaria?:

Código Delphi [-]
   ADOQuery1.Active:= False;
   ADOQuery1.SQL.Text:= 'SELECT DISTINCTROW Factura.Fecha, Factura.Terminos, Sum(Factura.MntTotal) AS SumaDeMntTotal '+
                        ' FROM Factura '+
                        ' WHERE Factura.Fecha = :Fecha AND Factura.Terminos = :Termino '+
                        ' GROUP BY Factura.Fecha, Factura.Terminos ';
   ADOQuery1.Active:= True;
   ADOQuery1.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery1.Parameters[1].Value:= 'Contado';

   ADOQuery2.Active:= False;
   ADOQuery2.Active:= True;
   ADOQuery2.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery2.Parameters[1].Value:= 'Credito';

   ADOQuery3.Active:= False;
   ADOQuery3.SQL.Text:= 'SELECT DISTINCTROW PagosAdelanto.FechaTransac, Sum(PagosAdelanto.MontoCompra) AS [Suma De MontoCompra], Sum(PagosAdelanto.Abono) AS [Suma De Abono] '+
                        ' FROM PagosAdelanto'+
                        ' WHERE PagosAdelanto.FechaTransac = :FechaTransac'+
                        ' GROUP BY PagosAdelanto.FechaTransac ';
   ADOQuery3.Active:= True;
   ADOQuery3.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery4.Active:= False;
   ADOQuery4.SQL.Text:= 'SELECT DISTINCTROW BancoNac.FechaTransac, Sum(BancoNac.Retiros) AS [Suma De Retiros], Sum(BancoNac.Depositos) AS [Suma De Depositos] '+
                        ' FROM BancoNac'+
                        ' WHERE BancoNac.FechaTransac = :FechaTransac'+
                        ' GROUP BY BancoNac.FechaTransac ';
   ADOQuery4.Active:= True;
   ADOQuery4.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery5.Active:= False;
   ADOQuery5.SQL.Text:= 'SELECT DISTINCTROW BancoSanJoseco.FechaTransac, Sum(BancoSanJoseco.Retiros) AS [Suma De Retiros], Sum(BancoSanJoseco.Depositos) AS [Suma De Depositos] '+
                        'FROM BancoSanJoseco'+
                        ' WHERE BancoSanJoseco.FechaTransac = :FechaTransac'+
                        ' GROUP BY BancoSanJoseco.FechaTransac ';
   ADOQuery5.Active:= True;
   ADOQuery5.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery6.Active:= False;
   ADOQuery6.SQL.Text:= 'SELECT DISTINCTROW BancoSanJosedol.FechaTransac, Sum(BancoSanJosedol.Retiros) AS [Suma De Retiros], Sum(BancoSanJosedol.Depositos) AS [Suma De Depositos] '+
                        ' FROM BancoSanJosedol'+
                        ' WHERE BancoSanJosedol.FechaTransac = :FechaTransac'+
                        ' GROUP BY BancoSanJosedol.FechaTransac ';
   ADOQuery6.Active:= True;
   ADOQuery6.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery7.Active:= False;
   ADOQuery7.SQL.Text:= 'SELECT DISTINCTROW CxPDetalle.FechaPago, CxPDetalle.TipoTransac, Sum(CxPDetalle.Monto) AS [Suma De Monto] '+
                        ' FROM CxPDetalle'+
                        ' WHERE CxPDetalle.FechaPago = :FechaPago AND CxPDetalle.TipoTransac ="PA" '+
                        ' GROUP BY CxPDetalle.FechaPago, CxPDetalle.TipoTransac';
   ADOQuery7.Active:= True;
   ADOQuery7.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
   ADOQuery8.Active:= False;
   ADOQuery8.SQL.Text:= 'SELECT DISTINCTROW CxCDetalle.FechaCobro, CxCDetalle.TipoTransac, Sum(CxCDetalle.Monto) AS [Suma De Monto] '+
                        ' FROM CxCDetalle'+
                        ' WHERE CxCDetalle.FechaCobro = :FechaCobro AND CxCDetalle.TipoTransac ="PA" '+
                        ' GROUP BY CxCDetalle.FechaCobro, CxCDetalle.TipoTransac';
   ADOQuery8.Active:= True;
   ADOQuery8.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));

Caral 02-03-2007 23:44:32

Hola
Tienes toda la razon jhonny y queda mas claro el codigo y legible.
Muchas gracias por el tiempo que me disteis, la verdad ya me tenia un poco loco esto.
Gracias Maestro.
Saludos

vtdeleon 02-03-2007 23:47:33

No entiendo como funciona al reves.
Código Delphi [-]
    ADOQuery1.Active:= True;
    ADOQuery1.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
Es decir, primero activas el Query y despues el parametro :confused:, No sabía que se podía hacer así.

Saludos

roman 02-03-2007 23:50:19

Pues a mi que me aspen pero no entiendo nada. ¿Cómo está eso de que primero activan la consulta y luego sustituyen los parámetros? ¿ESO funciona? :eek:;

// Saludos

jhonny 02-03-2007 23:51:52

Cita:

Empezado por vtdeleon
No enteindo como funciona al revez.

No se porque no había preguntado eso antes, pues de hecho cuando puse ese código al revés inmediatamente caí en cuenta lo edite y lo coloque al derecho, pero luego Caral dijo que funciono y bueno yo también me quede medio enredado.

vtdeleon 02-03-2007 23:52:55

Estamos todos enliado:D. Caral danos luz!

Caral 03-03-2007 00:01:01

Hola
Pues cosas de la vida insolitas, cuando me disteis el codigo pense exactamente lo mismo, aun asi lo coloque como estaba y funciona, como, no se, revisando mi codigo en otros form, cuando uso parametros, primero uso el parametro y luego activo la consulta, asi:
Ejemplo de un codigo:
Código Delphi [-]
 begin
      try
         QRTransPend:=TQRTransPend.Create(self);
          begin
          QRTransPend.ADOQuery1.Parameters[0].Value := Edit3.Text;
          QRTransPend.ADOQuery1.Parameters[1].Value := Edit4.Text;
         end;
         QRTransPend.ADOQuery1.Open;
         If RadioGroup1.ItemIndex = 0 then QRTransPend.Print
         else QRTransPend.Preview;
      finally
         QRTransPend.Free;
      end;
Preguntais a este novato:D , que dificil.:D
Para mi es que me quiere tanto delphi que hace todo lo posible para servir sea como sea.:D
Saludos

roman 03-03-2007 00:01:35

Pero además, me parece que DEBERÍA funcionar sin tanta conversión:

Código Delphi [-]
ADOQuery1.Parameters[0].Value:= StrToDate(DateToStr(DTP1.Date));
ADOQuery1.Active:= True;

esto es, como mencionaba Van Troi:

Código Delphi [-]
ADOQuery1.Parameters[0].Value:= DTP1.Date;
ADOQuery1.Active:= True;

pues en el primer caso regresamos a un tipo TDate.

Pero, ¡no funciona! ¿Y saben por qué? ¡Porque el valor de DTP1.Date no es un Date! Tiene la parte fracionaria del tiempo. ¿No se supone que debería estar truncado? ¿Será que me falta aplicar algún parche al Delphi?

// Saludos

Caral 03-03-2007 00:04:00

Nota curiosa:
Acabo de invertir el parametro en una consulta y tambien funciona, osea al reves y al derecho.
Delphi, eres genial.:D
Hay que preguntar esto a Borland.:D
Saludos

vtdeleon 03-03-2007 00:07:52

Tienes razon, lo trae todo. Lo probe con el Turbo.

vtdeleon 03-03-2007 00:12:14

Me dá, que si se aplica esto:
Código Delphi [-]
ADOQuery1.Parameters.ParamByName('fecha').DataType:=ftDate
deberia funcionar sin la conversión.

roman 03-03-2007 00:16:36

Pues no. Al menos en mi caso, si pongo

Código Delphi [-]
ADOQuery1.Active := false;

ADOQuery1.Parameters.ParamByName('fecha').DataType := ftDate;
ADOQuery1.Parameters.ParamValues['fecha'] := DateTimePicker1.Date;

ADOQuery1.Active := true;

no funciona. Pero si pongo

Código Delphi [-]
ADOQuery1.Active := false;

ADOQuery1.Parameters.ParamByName('fecha').DataType := ftDate;
ADOQuery1.Parameters.ParamValues['fecha'] := Trunc(DateTimePicker1.Date);

ADOQuery1.Active := true;

funciona bien. Incluso puedo quitar la asignación del tipo de datos:

Código Delphi [-]
ADOQuery1.Active := false;

ADOQuery1.Parameters.ParamValues['fecha'] := Trunc(DateTimePicker1.Date);

ADOQuery1.Active := true;

pero entonces me falla si quiero una segunda consulta con otro parámetro.

// Saludos

vtdeleon 03-03-2007 00:21:01

Cita:

Empezado por roman
Pero, ¡no funciona! ¿Y saben por qué? ¡Porque el valor de DTP1.Date no es un Date! Tiene la parte fracionaria del tiempo. ¿No se supone que debería estar truncado? ¿Será que me falta aplicar algún parche al Delphi?

Lo mismo sucede con MonthCalendar.


La franja horaria es GMT +2. Ahora son las 04:21:12.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi