Ver Mensaje Individual
  #1  
Antiguo 30-11-2012
Avatar de marcoszorrilla
marcoszorrilla marcoszorrilla is offline
Capo
 
Registrado: may 2003
Ubicación: Cantabria - España
Posts: 11.221
Reputación: 10
marcoszorrilla Va por buen camino
Como obtener equivalente de Last en Firebird

Tengo este SQL en Firebird 2.5, y me piden añadir el último precio, pero observo que no existe la instrucción Last.

Código Delphi [-]
procedure TfrPcons1Cli.btAceptarClick(Sender: TObject);
begin
IbDtsV.Close;
IbDtsV.SelectSQL.Clear;
IbDtsV.SelectSQL.Add('Select Max(Codclient) as Codclient, Max(Fecha) as Fecha, ');
IbDtsV.SelectSQL.Add('Producto, Sum(Unidades) as Unidades,');
IbDtsV.SelectSQL.Add('Max(Precio) as Precio, Sum(Subtotal) as Subtotal, ');
IbDtsV.SelectSQL.Add('Avg(Precio) as PMedio, Min(Precio) as MPrecio');
IbDtsV.SelectSQL.Add('from LineasVentas');
IbDtsV.SelectSQL.Add('Where Codclient = :C');
IbDtsV.SelectSQL.Add('And Fecha between :F1 and :F2');
IbDtsV.SelectSQL.Add('Group By Producto');
IbDtsV.SelectSQL.Add('Having Sum(Unidades) <> 0');
IbDtsV.SelectSQL.Add('Order by Producto');

IbDtsV.ParamByName('C').AsString:=IbDTSCliCodigo.Value;
IbDtsV.ParamByName('F1').AsDate:=DateOf(DtpkIni.Date);
IbDtsV.ParamByName('F2').AsDate:=DateOf(DtpkFin.Date);
IbDtsV.open;
end;

Quisiera:
Código Delphi [-]
procedure TfrPcons1Cli.btAceptarClick(Sender: TObject);
begin
IbDtsV.Close;
IbDtsV.SelectSQL.Clear;
IbDtsV.SelectSQL.Add('Select Max(Codclient) as Codclient, Max(Fecha) as Fecha, ');
IbDtsV.SelectSQL.Add('Producto, Sum(Unidades) as Unidades,');
IbDtsV.SelectSQL.Add('Max(Precio) as Precio, Sum(Subtotal) as Subtotal, ');
IbDtsV.SelectSQL.Add('Avg(Precio) as PMedio, Min(Precio) as MPrecio,');
IbDtsV.SelectSQL.Add('Last(Precio) as UltimoP');
IbDtsV.SelectSQL.Add('from LineasVentas');
IbDtsV.SelectSQL.Add('Where Codclient = :C');
IbDtsV.SelectSQL.Add('And Fecha between :F1 and :F2');
IbDtsV.SelectSQL.Add('Group By Producto');
IbDtsV.SelectSQL.Add('Having Sum(Unidades) <> 0');
IbDtsV.SelectSQL.Add('Order by Producto');

IbDtsV.ParamByName('C').AsString:=IbDTSCliCodigo.Value;
IbDtsV.ParamByName('F1').AsDate:=DateOf(DtpkIni.Date);
IbDtsV.ParamByName('F2').AsDate:=DateOf(DtpkFin.Date);
IbDtsV.open;
end;

Un Saludo.
__________________
Guía de Estilo de los Foros
Cita:
- Ça c'est la caisse. Le mouton que tu veux est dedans.
Responder Con Cita