Formatting numeric collumn

  • Hi, dear

    I need to execute a query to get a numeric (9) collumn and return a string ('000000001').

    How can I get it?

    Thank you very much.

    Obede

    Brazil

  • Just to clarify, you want to retrieve a number and pad it with leading zeros to ensure the value returned is always 9 characters long ?

    If so then maybe you could do something like:


    DECLARE @Number int

    SET @Number = 1

    SELECT RIGHT('000000000' + CAST(@Number AS varchar),9) AS Formatted


  • This is a foramtting task.. Do that with the app, not the server.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply