Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL FIxed-Width Output

Is there a way to get SQL Server to output a string with a fixed width? For example

SELECT FixedWidth(cola, 7), FixedWidth(colb, 10) ...

That would output 2 strings with 7 and 10 characters wide repsectively? Something like

'test   ' 'foobar    '
'aabbb  ' 'hello     '
'foo    ' 'bar       '
like image 635
Jim Mitchener Avatar asked Sep 02 '26 19:09

Jim Mitchener


1 Answers

  SELECT 
       CAST(cola as char(7)) as cola, 
       CAST(colb as char(10)) as colb ....
like image 95
Martin Smith Avatar answered Sep 05 '26 16:09

Martin Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!