Amass

How to Left-Pad a field in MSSQL

May 28th, 2008 Luke

I recently encountered a situation where I needed to left-pad a string to a certain number of characters with 0’s. This is the SQL to do it:

RIGHT('000' + rtrim(column_name),3)

The ‘000′ is your padding characters, column_name is what you’re padding, and the 3 is how many characters you want back.