Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL 6.5 string padder 2

Status
Not open for further replies.

Omnillas

Programmer
May 4, 2004
29
US
I've recently taken over a database that has SQL server 6.5 compatibility set due to the nature of the vendor. I am to write a few scripts to dump some of the data for a 3rd party. This data, of course, needs to be fixed width text.

Does anyone have any recommendations for a good string padding routine? Can't take advantage of user defined functions. :(

Basically would like to be able to pad a string either left or right side with any character I choose.
 
You can use Len() and Replicate():
Code:
''This example assumes you want a string a length of 20 chars.
declare @test varchar(20)
set @test = 'This is a Test'

select replicate ('%', 20 - Len(@test)) + @test --Pads to the left.
select @test + replicate ('%', 20 - Len(@test)) --Pad to the right
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top