Ver Mensaje Individual
  #12  
Antiguo 13-07-2008
Gallosuarez Gallosuarez is offline
Miembro
 
Registrado: feb 2007
Posts: 92
Reputación: 18
Gallosuarez Va por buen camino
Post Mejores Clientes...

Crea el siguiente procedimiento:

Código SQL [-]
create procedure MejoresClientes(Rango integer)
returns (IDCliente int, Nombre varchar(60), DNI varchar(20), CntVentas int) as
begin
  for select C.IDCLIENTE, NOMBRE, DNI, count(IDVENTA)
      from (CLIENTE C inner join VENTA V on C.IDCLIENTE = V.IDCLIENTE) 
      group by NOMBRE, DNI, C.IDCLIENTE
      having count(IDVENTA) > 0 
      order by 4 desc
      into :IDCliente, :Nombre, :CNI, CntVentas do
  begin
    suspend;
    Rango = Rango - 1;
    if (Rango = 0) then exit;
  end
end
Y lo llamas así:

Código SQL [-]
select * from MejoresClientes(10)

Saludos y nos platicas como te fue...
Gerardo Suárez Trejo. (Y si te sacas diez de calificación en la tesis: 5 para tí y 5 para mi )

Última edición por Gallosuarez fecha: 13-07-2008 a las 19:23:54.
Responder Con Cita