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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Padding with trailing spaces 1

Status
Not open for further replies.

dukeslater

Technical User
Jan 16, 2001
87
US
I need to export to a text file with specified column positions, meaning that I need to right pad the results with spaces. I don't recall any problems in the past doing this, but this time I'm not getting the proper results. For example all of these return the length value of 4:

create table testtable (chartest char(8),
vartest varchar(8))

insert into testtable values ('8888 ','8888 ')

select
len(chartest + replicate(' ',4)),
len(vartest + replicate(' ',4)),
len(cast(vartest As Nchar(15))),
len(cast(chartest As Nchar(15))),
len(chartest),
len(vartest)
from testtable

I'm wondering now if there is some system setting that determines how SQL Server handles trailing spaces, but I'm only finding options for null.

This returns a value of 8, which is what I would expect:

len(replicate(' ',4) + chartest)

Thanks in advance for your help.


 
As usual, I wish I'd posted this yesterday. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top