Results 1 to 3 of 3
  1. #1
    Join Date
    May 2011

    Unanswered: 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:


    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.

    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,

  2. #2
    Join Date
    Jun 2003
    Toronto, Canada
    Provided Answers: 1
    export to myfile.txt of del 
     modified by nochardel 
      cast('john' as char(10)) || 
      cast('smith' as char(20)) || 
      etc etc
     from mytable

  3. #3
    Join Date
    May 2011
    Thank you.
    I had suspected cast might be involved.
    I'll put it to use immediately and see how I go.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts