Space between characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lenygold via DBMonster.com

    Space between characters

    I HAVE A STRING: ABCDEFG

    HOW TO INSERT A SPACE BETWEEN ALL CHARACTERS?
    REQUESTED OUTPUT:

    A B C D E F G

    Thank's in advance Leny G.

    --
    Message posted via DBMonster.com


  • Dan van Ginhoven

    #2
    Re: Space between characters

    Hi!
    If you have a fixed number of characters you can use
    INSERT(INSERT(I NSERT(INSERT(IN SERT(INSERT('AB CDEFG',2,0,' '),4,0,' '),6,0,' '),8,0,' '),10,0,' '),12,0,' ')
    else you will want a stored procedure or UDF looping over the length of the string doing for instance an insert
    /dg

    "lenygold via DBMonster.com" <u41482@uwewrot e in message news:837fb3b2f4 e25@uwe...
    I HAVE A STRING: ABCDEFG
    >
    HOW TO INSERT A SPACE BETWEEN ALL CHARACTERS?
    REQUESTED OUTPUT:
    >
    A B C D E F G
    >
    Thank's in advance Leny G.
    >
    --
    Message posted via DBMonster.com

    >

    Comment

    • Dave Hughes

      #3
      Re: Space between characters

      lenygold via DBMonster.com wrote:
      I HAVE A STRING: ABCDEFG
      >
      HOW TO INSERT A SPACE BETWEEN ALL CHARACTERS?
      REQUESTED OUTPUT:
      >
      A B C D E F G
      >
      Thank's in advance Leny G.
      The TRANSLATE function [1] can be handy for this:

      VALUES TRANSLATE('A B C D E F G H', SOMESTRING, 'ABCDEFGH')

      For example:

      SELECT
      TRANSLATE('A B C D E F G H', S, 'ABCDEFGH')
      FROM (
      VALUES
      ('ABCD'),
      ('1234'),
      ('Testing')
      ) AS T(S)

      Outputs:


      1
      ---------------
      A B C D
      1 2 3 4
      T e s t i n g

      3 record(s) selected.


      Just expand the first and third parameters with more characters if
      extra length is required.


      [1]

      uw.sql.ref.doc/doc/r0000862.html


      Cheers,

      Dave.

      Comment

      • lenygold via DBMonster.com

        #4
        Re: Space between characters

        Thank you. Translate is working
        Dave Hughes wrote:
        >I HAVE A STRING: ABCDEFG
        >>
        >[quoted text clipped - 4 lines]
        >>
        >Thank's in advance Leny G.
        >
        >The TRANSLATE function [1] can be handy for this:
        >
        >VALUES TRANSLATE('A B C D E F G H', SOMESTRING, 'ABCDEFGH')
        >
        >For example:
        >
        >SELECT
        TRANSLATE('A B C D E F G H', S, 'ABCDEFGH')
        >FROM (
        VALUES
        ('ABCD'),
        ('1234'),
        ('Testing')
        ) AS T(S)
        >
        >Outputs:
        >
        >1
        >---------------
        >A B C D
        >1 2 3 4
        >T e s t i n g
        >
        3 record(s) selected.
        >
        >Just expand the first and third parameters with more characters if
        >extra length is required.
        >
        >[1]
        >http://publib.boulder.ibm.com/infoce.../com.ibm.db2.l
        >uw.sql.ref.d oc/doc/r0000862.html
        >
        >Cheers,
        >
        >Dave.
        --
        Message posted via http://www.dbmonster.com

        Comment

        Working...