I have a string that is up to 3 characters long when it\'s first created in SQL Server 2008 R2.
I would like to pad it with leading zeros, so if its original value w
For a more dynamic approach try this.
declare @val varchar(5) declare @maxSpaces int set @maxSpaces = 3 set @val = '3' select concat(REPLICATE('0',@maxSpaces-len(@val)),@val)