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!

Fixing the width in SQL

Status
Not open for further replies.

mike718

Programmer
Jul 7, 2004
58
US
I have the constant task of producing flat files with fixed widths. I would like to know is there a way that I can create fixed widths in SQL no matter the length of the data in the record. For example if I have a name column that is 20 spaces, and enter in a name that is 11 spaces, I would still like to have the other 9 spaces populated. So if I run a query and save the query as a csv file it would save as "Christopher ",...
Thanks a bunch.
 
One way: by using CAST orCONVERT:

select cast( 'Christopher' as char(20) )
 
I think the char datatype should do this. It will however use more space as every record requires the full space, rather than a varchar column which only uses the number of characters it contains.

An alternative could be to use VBScript (in dts) to append whitespace to the relevant records...

James Goodman MCSE, MCDBA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top