If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Exporting to text file of varied but fixed width columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-19-11, 18:32
mrvinch mrvinch is offline
Registered User
 
Join Date: May 2011
Posts: 2
Exporting to text file of varied but fixed width columns

Hi all,

I am not familiar with DB2, I live in the land of php and mysql and have come here hoping some fine folk could suggest a solution to the following. I have been searching but either I'm not using the correct terminology or this task isn't one that cause others' grief, because I can't seen to get close to a solution.

I have a client that requires text file output of select data presented as a series of fixed width columns.

For example the csv version of the output would look something like this:

john,smith,23,staples,street

However I need to produce the output as

john smith 23 staples street

where the first column is a total of 10 characters wide and john consumes the first four and the remaining 6 are space characters.
where the second column is a total of 20 characters and smith consumes the first five and the remaining 15 are space characters.
etc
etc

The database is DB2 v8 on Windows Server 2008

I am hoping for a SELECT / EXPORT style query that will produce the output in one step, but I'd be equally happy with a .csv file manipulation solution.

Would anyone have any advice on how to achieve the fixed width output by any method?

Thanks in advance,
Nicholas
Reply With Quote
  #2 (permalink)  
Old 05-19-11, 21:54
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Code:
export to myfile.txt of del 
 modified by nochardel 
 select 
  cast('john' as char(10)) || 
  cast('smith' as char(20)) || 
  etc etc
 from mytable
Reply With Quote
  #3 (permalink)  
Old 05-20-11, 11:13
mrvinch mrvinch is offline
Registered User
 
Join Date: May 2011
Posts: 2
Thank you.
I had suspected cast might be involved.
I'll put it to use immediately and see how I go.
Cheers,
Nicholas
Reply With Quote
Reply

Tags
db2, fixed width

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On