This is a variant of the version that I use. I've modified it to use the same arguments as the one given in the article. I liked the comment given about a center orientation. Perhaps I'll modify this to include that feature as well.
-- =============================================
-- Author:Aaron N. Cutshall
-- Create date: 21-Apr-2008
-- Description:Pad string with given character for length given
-- =============================================
ALTER FUNCTION fn_PadStr(
@OrigStr varchar(512),
@PadChar char(1) = ' ',
@Length int,
@Orientation char(1) = 'L')
RETURNS varchar(512)
AS
BEGIN
RETURN CASE WHEN @Orientation = 'R' THEN @OrigStr ELSE '' END +
REPLICATE(@PadChar, @Length - LEN(@OrigStr)) +
CASE WHEN @Orientation = 'L' THEN @OrigStr ELSE '' END
END
LinkedIn: http://www.linkedin.com/in/sqlrv
Twitter: http://www.twitter.com/sqlrv
Website: http://sqlrv.com