MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Concatination within the SELECT statement

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
ravikirti
Beginner


Joined: 13 Sep 2004
Posts: 3
Topics: 1
Location: Bangalore

PostPosted: Wed Dec 22, 2004 4:31 am    Post subject: Concatination within the SELECT statement Reply with quote

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
View user's profile Send private message
ravikirti
Beginner


Joined: 13 Sep 2004
Posts: 3
Topics: 1
Location: Bangalore

PostPosted: Wed Dec 22, 2004 4:38 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Dec 22, 2004 5:17 am    Post subject: Reply with quote

Ravikirti,

You should use the RTRIM function which removes the trailing spaces from a column.

try this sql
Code:

SELECT RTRIM(column-1) CONCAT
       CHAR(' ')   CONCAT
       RTRIM(column-2)   
  FROM TABLE                                   
;                                                                   


Check this link for a detailed explanation of RTRIM

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/3.2.71?SHELF=&DT=20010718164132&CASE=

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ravikirti
Beginner


Joined: 13 Sep 2004
Posts: 3
Topics: 1
Location: Bangalore

PostPosted: Wed Dec 22, 2004 5:46 am    Post subject: Reply with quote

Thanks ..it worked...............


regards
ravikirti
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 22, 2004 6:02 am    Post subject: Reply with quote

Thanks for the solution Kolusu.

Phantom
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Dec 22, 2004 11:55 am    Post subject: Reply with quote

This will also work:

SELECT RTRIM(LNAME) || ' '||
SUBSTR(FNAME,1,12) AS NAME
FROM TABLE
WHERE ....
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 22, 2004 12:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Dec 22, 2004 12:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 22, 2004 12:37 pm    Post subject: Reply with quote

Thanks for the clarification kolusu,

Regards,
Phantom
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Dec 22, 2004 2:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group