Ver Mensaje Individual
  #1  
Antiguo 03-07-2020
pepesoft pepesoft is offline
Miembro
 
Registrado: ago 2014
Posts: 15
Reputación: 0
pepesoft Va por buen camino
Ayuda con SQL

Hola, tengo un caso de una consulta que es la siguiente
Código Delphi [-]
var
  tValor, tNumero: Integer;
  tText :string;
begin
  tTUni := TUniQuery.Create(nil);
  tTUni.Connection := DBConexion.BaseDatos;

  tText  := 'TPT';
  tValor := 1;

  with Uniquery do
  begin

    Close;
    SQL.Clear;
    SQL.Add('SELECT MAX(SUBSTR(codigo,4))::integer + 1 AS numero FROM clientes');
    SQL.Add(' WHERE LEFT(codigo,3) = :texto ');
    ParamByName('texto').AsString := tText;
    Open;
    tNumero  := FieldByName('numero').AsInteger;
    if tNumero > 0 then
      Edit1.Text := tText + FormatFloat( '#',(tNumero) )
    else
      Edit1.Text := tText + FormatFloat( '#',tValor );
   end;

end;
Lo que sucede es que quiero generar un código alfanumerico en postgresql, que contenga 3 letras y numeros, algo asi
TPT1, TPT2, ..., .., TPT100, .., TPT2300, así sucesivamente. con este código solo genera hasta el numero diez y luego todos son 10, algo esta fallando y no me he dado cuenta.
Responder Con Cita