Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-05-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 27
Caral Va por buen camino
Hola
Sumar el total y mostrarlo en un edit.
Código Delphi [-]
procedure TfrmVentasConsulta.btnBuscarClick(Sender: TObject);
begin
    //if(VerificaDatos) then begin
        dmDatos.cdsCliente.Active := false;
        with dmDatos.qryListados do begin
            Close;
            SQL.Clear;
            SQL.Add('SELECT caja, numero, fecha, hora, estatus, total-iva AS subtotal, ');
            SQL.Add('iva, Total, Sum(total) As GTotal, cliente, clave FROM ventas v WHERE 1 = 1 ');

            if(chkCliente.Checked) then
                SQL.Add('AND cliente IN (SELECT clave FROM clientes WHERE nombre LIKE ''%' + txtClienteBusq.Text + '%'') ');

            if(chkFecha.Checked) then begin
                SQL.Add('AND fecha >= ' + quotedstr(datetostr(FechaBusq.date)));
                //SQL.Add('AND fecha <= ''' + txtMesFin.Text + '/' + txtDiaFin.Text + '/' + txtAnioFin.Text + '''');
            end;
            Open;
            // Muestro el dato en un edit.
            Edit1.Text:= dmDatos.cdsCliente.Filebyname('GTotal').Value;
        end;
Saludos
PD: Mas o menos
__________________
Siempre Novato
Responder Con Cita
  #2  
Antiguo 07-05-2011
Rofocale Rofocale is offline
Miembro
 
Registrado: mar 2010
Posts: 182
Poder: 17
Rofocale Va por buen camino
no puedo al agregar lo que me has puesto caral me sale error al apretar el boton buscar me dice : invalid expression in the select list(not contained in either an aggregate function or the GROUP by clause)
Responder Con Cita
  #3  
Antiguo 07-05-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 27
Caral Va por buen camino
Hola
Hace falta el group by en la sentencia, eso es todo.
Saludos
Edito:
Al hacer dos select uno dentro del otro, se necesita definir un Group by, ya que no se define de que tabla se hara la suma.
Me parece una consulta sencilla, pero hecha a lo dificil.
__________________
Siempre Novato

Última edición por Caral fecha: 07-05-2011 a las 19:58:31.
Responder Con Cita
  #4  
Antiguo 07-05-2011
Rofocale Rofocale is offline
Miembro
 
Registrado: mar 2010
Posts: 182
Poder: 17
Rofocale Va por buen camino
no funciona bueno hize esto pero me suma todo osea al hacer click en el check y poner la fecha me lo filtra normal pero me suma todo sin distinguir que puse la fecha y solo sumar el resultado de acuerdo a la fecha

Nombre total Fecha
Jose 2.5 05/05/2011
Maria 3.5 05/05/2011
Carlos 1.5 06/05/2011

al filtrar para la fecha 5 sale solo jose y maria pero la suma sale 7.5 me suma todo cuando solo deberia de salir 6

Código Delphi [-]
     dmDatos.cdsCliente.Active := false;
        with dmDatos.qryListados do begin
            Close;
            SQL.Clear;
            SQL.Add('SELECT caja, numero, fecha, hora, estatus, total-iva AS subtotal,');
            SQL.Add('iva, total, cliente, clave FROM ventas v WHERE 1 = 1');

            if(chkCliente.Checked) then
                SQL.Add('AND cliente IN (SELECT clave FROM clientes WHERE nombre LIKE ''%' + txtClienteBusq.Text + '%'')');

            if(chkFecha.Checked) then begin
                SQL.Add('AND fecha = ' + quotedstr(datetostr(FechaBusq.date)));

                with dmDatos.qryConsulta do begin
                Close;
                SQL.Clear;
                SQL.Add('SELECT sum(total) AS total FROM ventas');
                Open;
                txtTotalventa.text := floattostr(FieldByName('total').AsFloat);
                end;
            end;
            open;
Responder Con Cita
  #5  
Antiguo 07-05-2011
Rofocale Rofocale is offline
Miembro
 
Registrado: mar 2010
Posts: 182
Poder: 17
Rofocale Va por buen camino
alguien me ayuda porfavor ?
Responder Con Cita
  #6  
Antiguo 08-05-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 27
Caral Va por buen camino
Hola
Código Delphi [-]
// primera consulta
dmDatos.cdsCliente.Active := false;
  with dmDatos.qryListados do begin
            Close;
            Text:= 'SELECT caja, numero, fecha, hora, estatus, total-iva AS subtotal,'+
                   'iva, total, cliente, clave FROM ventas v WHERE 1 = 1 ';

            if(chkCliente.Checked) then
            Begin
            SQL.Add('AND cliente IN (SELECT clave FROM clientes WHERE nombre LIKE ''%' + txtClienteBusq.Text + '%'')');
            end;
            if(chkFecha.Checked) then
            Begin
            SQL.Add('AND fecha = ' + quotedstr(datetostr(FechaBusq.date)));
            end;
 open;
 end;
  
// segunda consulta
with dmDatos.qryConsulta do begin
            Close;
            Text:= 'SELECT sum(total) AS total FROM ventas '+
                   'AND fecha = ' + quotedstr(datetostr(FechaBusq.date));
  Open;
  end;
// muestra dato
txtTotalventa.text := floattostr(FieldByName('total').AsFloat);
Saludos
__________________
Siempre Novato

Última edición por Caral fecha: 08-05-2011 a las 01:16:20.
Responder Con Cita
  #7  
Antiguo 09-05-2011
Rofocale Rofocale is offline
Miembro
 
Registrado: mar 2010
Posts: 182
Poder: 17
Rofocale Va por buen camino
Hola al compilar da error : no se puede asignar a una propiedad de solo lectura
Text:= 'SELECT.......
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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
sumar campos cmm07 Varios 2 23-03-2009 16:21:08
Sumar valores con stringgrid zero_dx Varios 2 16-10-2007 20:02:01
sumar columnas en stringgrid Choclito Varios 1 11-05-2006 15:26:59
Sumar los campos de 3 tablas luisreg SQL 2 28-01-2004 02:34:41
Sumar campos de una consulta? danytorres Varios 1 10-11-2003 15:52:57


La franja horaria es GMT +2. Ahora son las 15:59:49.


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
Copyright 1996-2007 Club Delphi