SDU Tools: LeftPad and RightPad in T-SQL (Right-align, Left-align)
Over the years, I’ve had a surprising number of questions on how to right-align a set of numbers using T-SQL.
The first concept that people seem to miss is that numbers aren’t strings. So there’s no concept of actually aligning a number, it’s only a string representation of a number that can be right-aligned or left-aligned. Or how it’s displayed in a client application.
But if you really want to create a string that has right-aligned numbers, then left padding of the number is what you want.
2017-12-22