Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert an int to a zero padded string in T-SQL?

Tags:

sql

tsql

Let's say I have an int with the value of 1. How can I convert that int to a zero padded string, such as 00000001?

like image 547
flipdoubt Avatar asked Nov 21 '08 15:11

flipdoubt


People also ask

How do you do padding in SQL?

LPAD() function in MySQL is used to pad or add a string to the left side of the original string. The actual string which is to be padded. If the length of the original string is larger than the len parameter, this function removes the overfloating characters from string.


1 Answers

Declare @MyInt integer Set @MyInt = 123 Declare @StrLen TinyInt Set @StrLen = 8  Select Replace(Str(@MyInt, @StrLen), ' ' , '0') 
like image 191
Charles Bretana Avatar answered Oct 06 '22 08:10

Charles Bretana