<p>We all know T-SQL's string manipulation capabilities sometimes leaves much to be desired...</p>

<p>I have a numeric field that needs to be output in T-SQL as a right-aligned text column. Example:</p>

<pre><code>Value
----------
   143.55
  3532.13
     1.75
</code></pre>

<p>How would you go about that? A good solution ought to be clear and compact, but remember there is such a thing as "too clever".</p>

<p>I agree this is the wrong place to do this, but sometimes we're stuck by forces outside our control.</p>

<p>Thank you.</p>

[{'answer_id': 56972, 'author': 'd91-jal', 'author_id': 5085, 'author_profile': 'https://Stackoverflow.com/users/5085', 'pm_score': 5, 'selected': True, 'text': '<p>The <a href="http://msdn.microsoft.com/en-us/library/ms189527.aspx" rel="noreferrer">STR function</a> has an optional length argument as well as a number-of-decimals one.</p>\n\n<pre><code>SELECT STR(123.45, 6, 1)\n\n------\n 123.5\n\n(1 row(s) affected)\n</code></pre>\n'}, {'answer_id': 56973, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 1, 'selected': False, 'text': "<p>If you MUST do this in SQL you can use the folowing code (This code assumes that you have no numerics that are bigger than 40 chars):</p>\n\n<pre><code>SELECT REPLICATE(' ', 40 - LEN(CAST(numColumn as varchar(40)))) + \nCAST(numColumn AS varchar(40)) FROM YourTable\n</code></pre>\n"}, {'answer_id': 56977, 'author': 'Josef', 'author_id': 5581, 'author_profile': 'https://Stackoverflow.com/users/5581', 'pm_score': 1, 'selected': False, 'text': "<p>The easiest way is to pad left:</p>\n\n<pre><code>CREATE FUNCTION PadLeft(@PadString nvarchar(100), @PadLength int)\nRETURNS nvarchar(200)\nAS\nbegin\nreturn  replicate(' ',@padlength-len(@PadString)) + @PadString\nend\ngo\nprint dbo.PadLeft('123.456', 20)\nprint dbo.PadLeft('1.23', 20)\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/56950', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2230/']