View previous topic :: View next topic |
Author |
Message |
ravikirti Beginner
Joined: 13 Sep 2004 Posts: 3 Topics: 1 Location: Bangalore
|
Posted: Wed Dec 22, 2004 4:31 am Post subject: Concatination within the SELECT statement |
|
|
I am trying to select two fields .. First_name and Last_name
i have been able to concat the two but am not able to remove the spaces in between.
For ex If the length of both the fields is 5
First name Last Name
RA DEV
SH PPP
The output for the concat command gives me the following
select concat(first_name,last_name) from tablename;
RA DEV
SH PPP
and the output for which i am looking is
RA DEV
SH PPP
Hope somebody replies to me as soon as possible.
Thanks
Ravi |
|
Back to top |
|
 |
ravikirti Beginner
Joined: 13 Sep 2004 Posts: 3 Topics: 1 Location: Bangalore
|
Posted: Wed Dec 22, 2004 4:38 am Post subject: |
|
|
am trying to select two fields .. First_name and Last_name
i have been able to concat the two but am not able to remove the spaces in between.
For ex If the length of both the fields is 5
the dot indicates blank spaces
First name Last Name
RA... DEV...
SH... PPP...
The output for the concat command gives me the following
select concat(first_name,last_name) from tablename;
RA... DEV...
SH... PPP...
and the output for which i am looking is
RA DEV
SH PPP
Hope somebody replies to me as soon as possible.
Thanks
Ravi |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
ravikirti Beginner
Joined: 13 Sep 2004 Posts: 3 Topics: 1 Location: Bangalore
|
Posted: Wed Dec 22, 2004 5:46 am Post subject: |
|
|
Thanks ..it worked...............
regards
ravikirti |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Wed Dec 22, 2004 6:02 am Post subject: |
|
|
Thanks for the solution Kolusu.
Phantom |
|
Back to top |
|
 |
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Wed Dec 22, 2004 11:55 am Post subject: |
|
|
This will also work:
SELECT RTRIM(LNAME) || ' '||
SUBSTR(FNAME,1,12) AS NAME
FROM TABLE
WHERE .... |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Wed Dec 22, 2004 12:12 pm Post subject: |
|
|
NASCAR9,
I'm not that familiar with DB2. I always use the pipe symbol '||' for concatenation in REXX. Is this the same in DB2 ?. How did u chose the length of FNAME to be 12 in ur code. Is that just an example to work with SUBSTR ?
Anyway the good thing is that, I learnt something new today. Thanks for that.
Regards,
Phantom |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Dec 22, 2004 12:18 pm Post subject: |
|
|
Quote: |
I always use the pipe symbol '||' for concatenation in REXX. Is this the same in DB2 ?.
|
Phantom,
'||' is a valid concatenation symbol even for DB2.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Wed Dec 22, 2004 12:37 pm Post subject: |
|
|
Thanks for the clarification kolusu,
Regards,
Phantom |
|
Back to top |
|
 |
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Wed Dec 22, 2004 2:23 pm Post subject: |
|
|
Phantom,
FNAME is just an example. A VB programmer in the shop showed me this select. The kid is Very sharp.
NASCAR9 |
|
Back to top |
|
 |
|
|