Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2009
    Posts
    16

    Unanswered: Adding character s to the column in db2

    Hi,


    I am new to db2.

    I have the below query in oracle:

    select column||"-"||1234||"-"||"LAST" from table where col2="something";

    Here the result of the above query will be like "value-1234-LAST"

    The same stuff I want in db2.

    How to add some numerics or characters to the column which we are selecting from the table?

    Please help me..

    Thanks in advance
    Last edited by rahul678; 11-11-09 at 09:12.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    If the data type of "column" is char, varchar, etc, then the code you have should work. If it is not a character string data type (e.g. integer, date), then you will need to convert it to a string before you can concatenate to it.

    Andy

  3. #3
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    9.7 provides you with implicit casting
    IBM DB2 9.7 for Linux, UNIX and Windows Information Center
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  4. #4
    Join Date
    Nov 2009
    Posts
    16
    in db2 its not working the query which I gave? Can you please give an example in db2?

  5. #5
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    May be .....
    column||'-'||'1234'||'-'||'LAST'

  6. #6
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Or simply
    column||'-1234-LAST'

  7. #7
    Join Date
    Nov 2009
    Posts
    16
    No tonkuma, it will not work in db2.
    In db2 we can give like
    select concat(concat(column1,1234),'LAST) from table
    But I need '-' in between those values..

    How to get the - in between the columns?

    Please help me..

  8. #8
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    What Tonkuma posted will work in DB2. Maybe you should post your actual query and the error you are getting. Also include what DB2 version and OS you are using.

    Andy

  9. #9
    Join Date
    Nov 2009
    Posts
    16
    ok I got it..

    Here is the query:

    select concat(concat(column1,'-'),1234) from table

    Thanks for ur rly..

  10. #10
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    '1234' .... i can see this in Tonkuma post
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  11. #11
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    How many RAHULs we have on the Forum ?

    All are brothers and sisters ?

    Lenny

Posting Permissions

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