How to put zeros after type checker - sql server

Asked

Viewed 35 times

-1

I need to put 9 zeros after 02:

0207200000053P 02- here comes the zeroes - 07200000053P

that is coming from a variable called @vNossoNumero. How do I do that?

Variable

Select  @vNossoNumero   = case when @Conta='0000064-7' then '16' else '02' end+RIGHT('00000000000' + convert(varchar,convert(bigint,@vSequencia) + 1),11)
  • pad

  • It would be interesting if you demonstrate the code you already have so we can help you

  • From the variable it returns like this: Select @vNossoNumero = case when @Account='0000064-7' then '16' Else '02' end+RIGHT('00000000000' + Convert(varchar,Convert(bigint,@vSequencia) + 1),11)

  • And the other string? comes from where and goes where?

1 answer

1


I think the solution lies in something like this:

SELECT LEFT(@vNossoNumero, 2) + REPLICATE('0', 9) + RIGHT(@vNossoNumero, LEN(@vNossoNumero) - 2)

Or so:

SELECT SUBSTRING(@vNossoNumero, 1, 2) + REPLICATE('0', 9) + SUBSTRING(@vNossoNumero, 3, LEN(@vNossoNumero))

In both cases the result serie, for example:

0200000000007200000053P

Browser other questions tagged

You are not signed in. Login or sign up in order to post.