single digit integer to '001' as varchar

  • Peeps,

    I have had several occasions to take a simple integer and convert it to a varchar that has two leading zeros. Is there an easy way to code this? Perferably a little more advanced so that if the integer only needs one or two leading zeros the code can help

    Current bodge:

    select

    'PLAYER' + '00' + PlayerNumber as PlayerName

    From PlayerDetails

    Alwas should deliver

    PLAYERnnn (where n is the PlayerNumber between 001 and 009)

    So expecting PlayerNumber to be between 1 and 9. While this is ok it does not cope if that playerNumber exceeds 9

    Is there a real easy simple way to do this?

    Cheers

    Ells

  • SELECT RIGHT('00'+CONVERT(varchar,1),3)

  • Many thanks. In knew there must be a blindingly obvious way.

    Cheers

    Ells

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

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