CREATE TABLE #Id( Id int)Insert into #IdValues (10),(12),(9),(15),(8),(4),(100),(29)Select Id,Right('000'+Convert(varchar,Id),3) from #Id