Leading Zero's

  • I did a search on this before I posted, but didn't find anything.

    I am using a procedure to return some data. Two of the fields are version type information, datatype of int. I'd like to return the data as a two digit value, so that a 1 would come out as 01.

    I thought there was a format command, but I can't seem to find it.

    Thanks in advance.

    Tom

  • You will need to pad that int with 0. I have a couple of examples on how to pad with zeroes here:

    http://www.geocities.com/sqlserverexamples/#string4

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • When you put a leading zero on the number it isn't a number anymore. Here is what I do.

    DECLARE @YourNumber INTEGER

    SET @YourNumber = 1

    SELECT RIGHT('00' + CONVERT(VARCHAR, @YourNumber), 2)

  • Thank you thank you...

    I ended up using:

    Right('00' + CONVERT(VARCHAR, table.version),2) AS version

    and it worked as advertised.

  • I have used that way as well but I also use

    REPLACE(STR(table.version,2,0),' ','0')

    don't know about performace though.

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 5 posts - 1 through 4 (of 4 total)

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