Try this: select right('00000' + cast(Your_Field as varchar(5)), 5)

It will get the result in 5 digits, ex: 00001,...., 01234

🌐
SQL Server Guides
sqlserverguides.com › convert-int-to-string-with-leading-zero-in-sql-server
How to Convert Int to String with Leading Zero in SQL Server? - SQL Server Guides
December 26, 2023 - As you can see in the output, the order_number column value is converted to a string with a leading zero. For example, 89 was the integer value in the order_number column, but after conversion, it becomes 00089, which contains three zeros at the beginning of the value. In this SQL Server tutorial, you learned how to convert int to string with leading zeros in SQL Server, where you learned about the meaning of leading zero.
Discussions

How To Add Leading Zeros In A Character String Converted From An Integer. - Databases & Queries - Spiceworks Community
Hello Every One, Need a little help, can any tell me how to add leading zeros In a character string which is basically converted from an integer. E.g. Int = 114 String = 114 { Convert(Char(6),114) } My need = 00114. How to add these two zeros at leading side. Regards, Khalid. More on community.spiceworks.com
🌐 community.spiceworks.com
0
June 29, 2004
How to convert or cast int to string in SQL Server - Stack Overflow
Looking at a column that holds last 4 of someone's SSN and the column was originally created as an int datatype. Now SSN that begin with 0 get registered as 0 on the database. How can I convert the More on stackoverflow.com
🌐 stackoverflow.com
COVERTING NUMERIC TO STRING, PRESERVING LEADING ZEROS – SQLServerCentral Forums
COVERTING NUMERIC TO STRING, PRESERVING LEADING ZEROS Forum – Learn more on SQLServerCentral More on sqlservercentral.com
🌐 sqlservercentral.com
October 30, 2008
t sql - T-SQL - CAST char with leading zeros to int - Stack Overflow
The result is an INT, which can be converted to a padded string. But the final result's type is string... ... sqlperformance.com/2015/06/t-sql-queries/…... Also, it's only working with 2012 or higher version. 2018-05-22T09:51:01.473Z+00:00 ... OP states: I'd like to convert char with leading zeros ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › cast-integer-to-character-with-leading-zeroes
CAST Integer to Character with leading zeroes – SQLServerCentral Forums
August 21, 2008 - REPLICATE(0, 6-len(CONVERT(varchar(6), integerfield1))) + CONVERT(Varchar(6), integerfield1) ... Is there a shorter method/function for creating these results. I absolutely need it to be a left justified number with leading zeroes because i and concatenating a string, number, sting and comparing ...
🌐
Spiceworks
community.spiceworks.com › programming & development › databases & queries
How To Add Leading Zeros In A Character String Converted From An Integer. - Databases & Queries - Spiceworks Community
June 29, 2004 - Hello Every One, Need a little help, can any tell me how to add leading zeros In a character string which is basically converted from an integer. E.g. Int = 114 String = 114 { Convert(Char(6),114) } My need = 00114. How …
🌐
w3tutorials
w3tutorials.net › blog › how-do-i-convert-an-int-to-a-zero-padded-string-in-t-sql
How to Convert an Int to a Zero-Padded String in T-SQL: Example for 1 to '00000001' — w3tutorials.net
DECLARE @int_value INT = 1; DECLARE @target_length INT = 8; SELECT FORMAT(@int_value, 'D' + CAST(@target_length AS VARCHAR)) AS ZeroPaddedString; ... FORMAT(1, 'D8') uses the 'D8' format string, where D = decimal and 8 = minimum length.
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › coverting-numeric-to-string-preserving-leading-zeros
COVERTING NUMERIC TO STRING, PRESERVING LEADING ZEROS – SQLServerCentral Forums
October 30, 2008 - SELECT convert(VARCHAR(30), SUBSTRING(convert(varchar(20), OPENDATE, 120), 0, 11) + ' ' + CAST(RIGHT(' 0'+ CAST(OPENHOURS AS VARCHAR(2)),2) + ':'+ RIGHT(' 0'+ CAST(OPENMINUTES AS VARCHAR(2)),2) + ':00' AS VARCHAR(10))) AS [Open DT][/font] _____________________________________________________________________________MCITP: Business Intelligence Developer (2005) ... Dave, check out a cleaner, reusable version at http://www.sqlservercentral.com/Forums/Topic594387-145-1.aspx
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1377398 › how-to-add-leading-zeros-to-exist-id
How to add leading zeros to exist id - Microsoft Q&A
September 27, 2023 - SELECT T.*,FORMAT(id,REPLICATE... leading zero, in no system. You have to convert it to a string, add some "0" at the front and take the right part in length as you want to have it, e.g....
🌐
MSSQLTips
mssqltips.com › home › sql convert int to string
SQL Convert INT to String
May 28, 2025 - In this article we cover different ways to convert a SQL Server numeric value into a string value using CAST, CONVERT, and CONCAT.
🌐
SQL Server Guides
sqlserverguides.com › sql-server-convert-int-to-string-padding
SQL Server Convert Int to String Padding - SQL Server Guides
November 8, 2023 - Also, make sure that the order ID should be six characters long and convert the order ID from integer to string. For that use the below query. SELECT OrderID, RIGHT('0000' + CONVERT(VARCHAR, OrderID),6) LeftPaddedOrderId FROM CustomerOrders; As you can see in the above output, all the value of the OrderID column is converted to a string with leading zeros which is six characters long.
🌐
IBM
community.ibm.com › community › user › discussion › how-to-convert-an-integer-into-a-string-while-retaining-the-leading-zeros
How to convert an integer into a string while retaining the leading zeros? | Programming Languages on Power
September 23, 2024 - I have an SQL service in IBM i which returns an integer. I need to convert it to a six digit string with the leading zeros.Using the number 1037 (which the ser
🌐
SQL Server Guides
sqlserverguides.com › convert-int-to-string-in-stored-procedure-in-sql-server
Convert Int to String in Stored Procedure in SQL Server - SQL Server Guides
November 6, 2023 - After calling or executing the Cast_IntToString procedure, it returns the output as 102, the converted string. In this SQL Server tutorial, you learned how to convert int to string in a stored procedure in SQL Server and learned about two methods CONVERT() and CAST(); using this method, you created a store procedure that converts int to string.
🌐
Database Guide
database.guide › add-leading-zeros-in-sql
Add Leading Zeros in SQL
November 10, 2021 - Below are examples of adding a leading zero to a number in SQL, using various DBMSs. Oracle has a TO_CHAR(number) function that allows us to add leading zeros to a number. It returns its result as a string in the specified format.
🌐
Tek-Tips
tek-tips.com › home › forums › software › programmers › dbms packages › microsoft sql server: programming
Leading zeros in an integer field | Tek-Tips
February 6, 2003 - Select CharVal=replace(str(IntCol,4),' ','0') You can insert ":" using the Stuff function. Select CharVal=Stuff(replace(str(IntCol,4),' ','0'),3,0,':') The STR function is handy because it right justifies whereas convert and cast to char or varchar left justifies the number.