I am trying to insert a record with 3 digits, example: if it is the first one that comes out 001 and the consecutive one is 002, when reaching 10! let 010 come out.
in my code what I achieve is that I insert it without the two zeros
declare @Resultado int
SELECT @Resultado = SUBSTRING(MAX(Agente), CHARINDEX('V', MAX(Agente)) + 1, 4) + 1
FROM Agente
WHERE Agente LIKE '%204%'
AND Tipo = 'Agente'
print @Resultado
insert into Agente
(Agente, Nombre, Estatus, Conciliar, Nomina, Logico1, Logico2, Equipo)
values
('204V' + Convert(varchar, @Resultado), 'Lalo Garcia', 'ALTA', 1, 1, 0, 0, 0)
end
I hope you can support me.
It is a simple solution.
You have a numeric variable, as a receiver of the number that comes from a query. Then if you leave only the 3 characters on the right to a string type variable filled with 3 zeros and concatenating what the numeric has, you already have the leading zeros.
in your code.
Format invoice numbers
Note : It is only supposed to hold 3 digits, and so the string variable is created with a varchar(6). If it can hold more, then you will have to size it larger and control the characters to be picked by the right function.