select...outfile...fixed length?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce D

    #1

    select...outfile...fixed length?

    I have query that I export into a file using the "outfile" syntax. I can
    use the following lines of code to create a delimited file but I want to
    know if I can create a fixed length file? Any ideas?

    delimited file:
    Select GivenName, Surname, Address, City, State, ZipCode
    into outfile 'xx.csv' fields terminated by ',' lines terminated by '\r\n'
    from kbm
    where zipcode = '12345'

    TIA
    -bruce duncan



  • Bruce D

    #2
    Re: select...outfil e...fixed length?

    "Bruce D" <brucexwxduncan x@hotmail.com> wrote in message
    news:10udf5ksju pgq13@corp.supe rnews.com...[color=blue]
    > I have query that I export into a file using the "outfile" syntax. I can
    > use the following lines of code to create a delimited file but I want to
    > know if I can create a fixed length file? Any ideas?
    >
    > delimited file:
    > Select GivenName, Surname, Address, City, State, ZipCode
    > into outfile 'xx.csv' fields terminated by ',' lines terminated by '\r\n'
    > from kbm
    > where zipcode = '12345'
    >
    > TIA
    > -bruce duncan
    >[/color]

    I figured out a way...but it's not perfect because I have to define the
    length...is there a way so that I don't have to use rpad()?

    Use rpad().
    Select rpad(GivenName, 15,' '), rpad(Surname,15 ,' '), rpad(Address,25 ,' ')
    into outfile 'xx.csv' fields terminated by ',' lines terminated by '\r\n'
    from kbm
    where zipcode = '12345'

    -bruce duncan


    Comment

    • Bruce D

      #3
      Re: select...outfil e...fixed length?

      > I figured out a way...but it's not perfect because I have to define the[color=blue]
      > length...is there a way so that I don't have to use rpad()?
      >
      > Use rpad().
      > Select rpad(GivenName, 15,' '), rpad(Surname,15 ,' '), rpad(Address,25 ,' ')
      > into outfile 'xx.csv' fields terminated by ',' lines terminated by '\r\n'
      > from kbm
      > where zipcode = '12345'
      >
      > -bruce duncan
      >[/color]

      Now I got it...if I just use "fields terminated by ''" it works just fine.
      That was easy....


      -bruce


      Comment

      Working...