Universal String Padder
SQL Server 2000: Tested
SQL Server 2005: Tested
SQL Server 2008: Tested
SQL Server 2008R2: Tested
SQL Server 2012: Not Tested
Author: Unknown/Richard Doering
Date: 29 Nov 2010
An odd little function that will allow any character string to be padded with single or multiple copies of the supplied character at either the beginning, middle, end or beginning and end.
There are actually 2 variants of this function
#1 Pads with a specified number of repetitions of a single character
#2 Pads with the number of repetitions of a single character until the resulting string is the specified length
Not a big difference between the two, but #2 would be more useful when producing a tabulation I think.
Might not get used very often, but very useful when they do.
I'm a great fan of formatting dynamic sql that I create for readability when debugging ie constructing the command string with spaces, tabs and CR/LF as per Stored Procedure code. This means that when I write the string to console, file or table for debugging or tracing, then the TSQL is easily readable. It makes for much more straightforward and less time-consuming debugging, especially when I return to the code after a while away.