• I don't know of a function in SQL that will format a number that way. I generally do something like this.

    Declare @i int

    Set @i = 23

    Select Right('0000' + Cast(@i as varchar(4)),4)