Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 11-05-2011
Rofocale Rofocale is offline
Miembro
 
Registrado: mar 2010
Posts: 182
Poder: 15
Rofocale Va por buen camino
ayuda problema con group by

Código Delphi [-]
   if(chkFecha.Checked) then
     begin
               dmDatos.cdsCliente.Active := false;
                with dmDatos.qryListados do begin
                if Active then Close;
                SQL.Clear;
                SQL.Add('SELECT f.caja,f.numero,f.fecha,f.hora,f.estatus,f.total-f.iva AS subtotal,f.iva,f.total,f.cliente,f.clave,sum(f.total) AS gtotal FROM ventas f WHERE f.fecha = :fecha GROUP BY f.caja,f.numero,f.fecha,f.hora,f.estatus,f.iva,f.total,f.cliente,f.clave');
                parambyname('fecha').AsDate := FechaBusq.date;
                open;
                end;

            with dmDatos.cdsCliente do begin
            Active := true;
            txtTotalventa.text := floattostr(FieldByName('gtotal').AsFloat);
            txtRegistros.text := inttostr(dmDatos.cdsCliente.RecordCount);
            FieldByName('caja').DisplayLabel := 'Caja';
            FieldByName('caja').DisplayWidth := 4;
            FieldByName('numero').DisplayLabel := 'Remisión';
            FieldByName('numero').DisplayWidth := 8;
            FieldByName('fecha').DisplayLabel := 'Fecha';
            FieldByName('fecha').DisplayWidth := 9;
            FieldByName('hora').DisplayLabel := 'Hora';
            FieldByName('hora').DisplayWidth := 11;
            FieldByName('estatus').DisplayLabel := 'Estatus';
            FieldByName('estatus').DisplayWidth := 7;
            FieldByName('subtotal').DisplayLabel := 'Subtotal';
            FieldByName('subtotal').DisplayWidth := 10;
           // (FieldByName('subtotal') as TNumericField).DisplayFormat := '#,##0.00';
            FieldByName('iva').DisplayLabel := 'IGV';
            FieldByName('iva').DisplayWidth := 10;
           // (FieldByName('iva') as TNumericField).DisplayFormat := '#,##0.00';
            FieldByName('total').DisplayLabel := 'Total';
            FieldByName('total').DisplayWidth := 10;
           // (FieldByName('total') as TNumericField).DisplayFormat := '#,##0.00';
            FieldByName('cliente').Visible := false;
          //  FieldByName('usuario').Visible := false;
            FieldByName('clave').Visible := False;
            FieldByName('gtotal').Visible := False;
           end;
    end
hola a todos este codigo utilizo para filtrar registros de una base de datos.. pero la parte sum(total) no me suma solo me devuelve el resultado del primer registro

Código Delphi [-]
SQL.Add('SELECT sum(f.total) AS gtotal FROM ventas f WHERE f.fecha = :fecha')

ese codigo filtra por fecha y me devuelve bien la suma de todos los registros de tal fecha

jose 2.5 05/05/2011
maria 2.5 05/05/2011
carla 1.0 06/05/2011

si lo filtro por fecha 5 solo sale en un text el total de gtotal que seria 5

todo bien ahi ahora como veran no solo necesito la suma del total en un edit si no que tmb me muestre el filtrado asi

jose 2.5 05/05/2011
maria 2.5 05/05/2011

ahora implemento el codigo asi

Código Delphi [-]
QL.Add('SELECT f.caja,f.numero,f.fecha,f.hora,f.estatus,f.total-f.iva AS subtotal,f.iva,f.total,f.cliente,f.clave,sum(f.total) AS gtotal FROM ventas f WHERE f.fecha = :fecha')

y como aumente todos los campos que se necesita para que se muestre ahora aparte de en un edit el total tambien en un GRID
me sale que necesito un group by clause

Código Delphi [-]
SQL.Add('SELECT f.caja,f.numero,f.fecha,f.hora,f.estatus,f.total-f.iva AS subtotal,f.iva,f.total,f.cliente,f.clave,sum(f.total) AS gtotal FROM ventas f WHERE f.fecha = :fecha GROUP BY f.caja,f.numero,f.fecha,f.hora,f.estatus,f.iva,f.total,f.cliente,f.clave');

lo implemento asi y me filtra bien me muestra los resultados si filtro por fecha 05/05/211 esto

jose 2.5 05/05/2011
maria 2.5 05/05/2011


pero en el edit me sale solo 2.5


ese es mi problema que ahora ya no me suma el total, creo que estoy haciendo algo mal con el group by

necesito que me ayuden porfavor muchas gracias de antemano
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Ayuda group by x fecha¡¡¡ Poke SQL 13 17-04-2010 14:43:58
Ayuda con group by nikotina SQL 5 23-06-2008 14:32:43
Problema con Group by david_uh Firebird e Interbase 2 13-04-2008 20:37:08
Problema con group by apicito SQL 7 23-05-2006 08:32:25
problema con group by raudelink SQL 2 18-10-2004 21:19:05


La franja horaria es GMT +2. Ahora son las 12:05:41.


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