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 > Adding character s to the column in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-09, 08:09
rahul678 rahul678 is offline
Registered User
 
Join Date: Nov 2009
Posts: 15
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 08:12.
Reply With Quote
  #2 (permalink)  
Old 11-11-09, 08:14
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
Reply With Quote
  #3 (permalink)  
Old 11-11-09, 08:20
rahul_s80 rahul_s80 is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 11-11-09, 08:22
rahul678 rahul678 is offline
Registered User
 
Join Date: Nov 2009
Posts: 15
in db2 its not working the query which I gave? Can you please give an example in db2?
Reply With Quote
  #5 (permalink)  
Old 11-11-09, 08:28
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
May be .....
column||'-'||'1234'||'-'||'LAST'
Reply With Quote
  #6 (permalink)  
Old 11-11-09, 08:30
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Or simply
column||'-1234-LAST'
Reply With Quote
  #7 (permalink)  
Old 11-11-09, 08:38
rahul678 rahul678 is offline
Registered User
 
Join Date: Nov 2009
Posts: 15
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..
Reply With Quote
  #8 (permalink)  
Old 11-11-09, 08:45
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
Reply With Quote
  #9 (permalink)  
Old 11-11-09, 08:45
rahul678 rahul678 is offline
Registered User
 
Join Date: Nov 2009
Posts: 15
ok I got it..

Here is the query:

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

Thanks for ur rly..
Reply With Quote
  #10 (permalink)  
Old 11-11-09, 09:09
rahul_s80 rahul_s80 is offline
Registered User
 
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
Reply With Quote
  #11 (permalink)  
Old 11-11-09, 09:50
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
How many RAHULs we have on the Forum ?

All are brothers and sisters ?

Lenny
Reply With Quote
Reply

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