IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Concatenating or Splitting the Column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gauravgupta2808
Warnings : 1

New User


Joined: 31 May 2007
Posts: 31
Location: Chennai, India

PostPosted: Wed Oct 17, 2007 2:17 pm
Reply with quote

Hi,
I have 2 tables:
Table A
CIN SORT ACCOUNT
A 10000 10001
A 10000 10002
B 10000 10001

Table B
ROUTER ID
A0000 1000010001
B1000 1000010002
C2000 1000010003

In table B the column ID is made by combining SORT & ACCOUNT.

I need to get the SORT , ACCOUNT & ROUTER of any CIN that is provided as input

Ex:
If CIN is A
10000 10001 A0000
10000 10002 B1000

If CIN is B
10000 10001 A0000

Could someone explain if we can Combine or Split the columns while comparing?
** ALL are numberic columns.
Back to top
View user's profile Send private message
raviprasath_kp
Warnings : 1

New User


Joined: 20 Feb 2005
Posts: 65
Location: chennai

PostPosted: Wed Oct 17, 2007 2:25 pm
Reply with quote

can u explain little bit more
bucause i cannot understand what u want exactly
Back to top
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


Joined: 31 May 2007
Posts: 31
Location: Chennai, India

PostPosted: Wed Oct 17, 2007 2:33 pm
Reply with quote

I need to get the Sort (table A) , Account (table A) & Router (table B) for any CIN (table A) provided as input.

Table A & Table B acn be joined on ID
where ID(table B) has combined SORT & ACCOUNT....
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Wed Oct 17, 2007 3:24 pm
Reply with quote

Hi Gaurav,

You can combine columns but I am not sure about spliting up of columns.


Use Concatenation OR STRING option.

Like this

Code:
SELECT SORT.A||ACCOUNT.A, ROUTER.B
FROM A, B
WHERE
CIN = :C-IN


Let us know if you have any doubt.
Eleborate your question so that someone can help you.
Back to top
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


Joined: 31 May 2007
Posts: 31
Location: Chennai, India

PostPosted: Wed Oct 17, 2007 3:41 pm
Reply with quote

Hi Hemant,

As i had mentioned, all are Numeric columns and || gives error.

Is there any way to convert number to string in DB2 and then i can concatenate
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Wed Oct 17, 2007 3:52 pm
Reply with quote

Hi Gaurav,

Quote:
A0000


Do you think this is an Numeric? Its ok.

But you can achieve this using Cobol-DB2 Programming Logic. Try out with Pgm, If you stuck out somewhere, Let us know...
Back to top
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


Joined: 31 May 2007
Posts: 31
Location: Chennai, India

PostPosted: Wed Oct 17, 2007 4:28 pm
Reply with quote

I am sorry for mentioning that A000 as number.. Actually i had put assumed data here.
Well I have got a solution and it is this...
Code:
SELECT                                                               
   ROUTER                                                         
FROM                                                                 
   TABLE B
WHERE                                                               
  B.ID  =                                                         
 (SELECT CONCAT(RTRIM(CHAR(SORT)), RTRIM(CHAR(ACCOUNT))) 
   FROM           TABLE A
   WHERE          CIN = <input>);     

                         



I have checked it and its working.. Only performance is a concern now icon_smile.gif

Thanks everyone who tried to help...
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Wed Oct 17, 2007 4:50 pm
Reply with quote

Hi Gaurav,

You're welcome.

Quote:
Well I have got a solution and it is this


Nice to hear. icon_lol.gif
Back to top
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


Joined: 31 May 2007
Posts: 31
Location: Chennai, India

PostPosted: Wed Oct 17, 2007 5:34 pm
Reply with quote

Hi Hemanth,

The CHAR function has a problem.

If the SORT is 01001 then CHAR(SORT) gives only 1001, due to which it is not being selected.

Can you help me retain the leading 0's when converting INTEGER to CHAR.

I dont mind if there is some other function available for the same. Thanks
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
No new posts Split a record with data in a differe... DFSORT/ICETOOL 8
Search our Forums:

Back to Top