To answer the question as asked: use something along the lines of the following:
DECLARE @Test VARCHAR(60),
@MaxLen INT,
@Len INT
SET @Test = 'This is a test.'
SET @Len = LEN(@Test)
SET @MaxLen = 30
SELECT @MaxLen,
'~' + @Test + '~',
'~' + @Test + REPLICATE(' ', @MaxLen - @Len) + '~'
However, unless there is a technical reason requiring you to use PRINT statements to output a result set to the Messages tab, you would be MUCH better off using one of the two following options without the CURSOR (both of which can do columnar format):
- SQLCMD command-line utility
- "Results to File" or "Results to Text" query output options