sql - Pad a number with zeros, but only if it's below a certain length? -


I have numbers that should be at least 7 digits long. For example:

  0000001 123456789 0012345   

All are valid I just need a pad with a number of 0 if its length is below. How do I do this in SQL Server? The best I've been able to get is the number pad if the length is less than 7 but on that, instead the number starts to decrease.

Post-text "itemprop =" text "> when command (convert (VARCHAR (12), column))> 7 then conversion (VARCHAR (12), column) ELSE Right ('0000000' + Convert (VARCHAR (12), column), 7) DODATABLE;

Comments