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 

Populate Primary code to secondary code rows using SQL

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


Joined: 24 Aug 2004
Posts: 21
Topics: 6

PostPosted: Tue Nov 15, 2005 9:54 pm    Post subject: Populate Primary code to secondary code rows using SQL Reply with quote

Table
-----
Scode char(5)
Pcode char(5)
type char(1) having values p/s
Code:

XXXXX   AAAAA   P
        BBBBB   S
        CCCCC   S
YYYYY   DDDDD   P
        EEEEE   S
        FFFFF   S
        GGGGG   S

Assume that we have data like the above in the table..
Can you provide me the query to get the result like the below..
Code:

PCODE   PCODE   TYPE
-----   -----   ----
AAAAA             P
BBBBB   AAAAA     S
CCCCC   CCCCC     S
DDDDD             P
EEEEE   DDDDD     S
FFFFF   DDDDD     S
GGGGG   DDDDD     S

Here is the explanation for the desired output..the result should contain all the pcodes and if the type of pcode is s it should have the corresponding pcode which the p in its type.

** I m trying to post the data in a formatted way..but I am unable to do it ...any suggestions for keeping the format...
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Tue Nov 15, 2005 11:18 pm    Post subject: sql query Reply with quote

Hai Dhulipalla,

The input data as well as desired output data provided you is unreadable format.Here is the solution if u want to display data in the format as it should have been ,you have to embed the data within the code tag and i have used color tag with green option and you have to close tags too.

For example in your case you should use:

Code:

XXXXX AAAAA P
BBBBB S
CCCCC S
YYYYY DDDDD P
EEEEE S
FFFFF S
GGGGG S



Similarly

Code:

PCODE PCODE TYPE
----- -----
AAAAA P
BBBBB AAAAA S
CCCCC CCCCC S
DDDDD P
EEEEE DDDDD S
FFFFF DDDDD S
GGGGG DDDDD S



Does the data formated by suits me your requirement ? Hope this helps.
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
dhulipalla
Beginner


Joined: 24 Aug 2004
Posts: 21
Topics: 6

PostPosted: Tue Nov 15, 2005 11:50 pm    Post subject: Reply with quote

Shekhar..I formatted my data..thanks for your suggestion..

Table
-----
Scode char(5)
Pcode char(5)
type char(1) having values p/s

Code:

XXXXX AAAAA P
      BBBBB S
      CCCCC S
YYYYY DDDDD P
      EEEEE S
      FFFFF S
      GGGGG S


Assume that we have data like the above in the table..
Can you provide me the query to get the result like the below..


Code:

PCODE PCODE TYPE
----- -----
AAAAA       P
BBBBB AAAAA S
CCCCC CCCCC S
DDDDD       P
EEEEE DDDDD S
FFFFF DDDDD S
GGGGG DDDDD S


Here is the explanation for the desired output..the result should contain all the pcodes and if the type of pcode is s it should have the corresponding pcode which the p in its type.
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 Nov 16, 2005 5:52 am    Post subject: Reply with quote

dhulipalla,

I have no idea about what you are trying to do. A better explanation would make it easier

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


Joined: 24 Aug 2004
Posts: 21
Topics: 6

PostPosted: Wed Nov 16, 2005 9:08 am    Post subject: Reply with quote

Kolusu,

I have a table with the following data where each SCODE is having multiple PCODEs with type P & S
Code:


SCODE   PCODE  TYPE
-----    -----  ---
XXXXX   AAAAA   P
        BBBBB   S
        CCCCC   S
YYYYY   DDDDD   P
        EEEEE   S
        FFFFF   S
        GGGGG   S


I want to list all the PCODEs in the first column and it should list the corresponding PCODE of type P in the second column.
Code:

OUTPUT

PCODE PCODE TYPE
----- -----
AAAAA AAAAA P
BBBBB AAAAA S
CCCCC AAAAA S
DDDDD DDDDD P
EEEEE DDDDD S
FFFFF DDDDD S
GGGGG DDDDD S


Here is the brief description of the requirement..
Code:

SCODE  PCODE  TYPE
-----  -----   ----
XXXXX   AAAAA   P
        BBBBB   S
        CCCCC   S
In this case XXXXX is having AAAAA as type P and BBBBB,CCCCC are of type C.

for this the output should look like
AAAAA AAAAA P
BBBBB AAAAA S
CCCCC AAAAA S


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 Nov 16, 2005 9:25 am    Post subject: Reply with quote

dhulipala,

How do you relate BBBBB and CCCCC records to scode of XXXXX ? There is no indicator to tag those records to scode of xxxxx

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


Joined: 24 Aug 2004
Posts: 21
Topics: 6

PostPosted: Wed Nov 16, 2005 9:40 am    Post subject: Reply with quote

Kolusu

We can tie the PCODE BBBBB, CCCCC with XXXXX.

Code:

SCODE  PCODE  TYPE
-----  -----   ----
XXXXX   AAAAA   P
XXXXX   BBBBB   S
XXXXX   CCCCC   S
In this case XXXXX is having AAAAA as type P and BBBBB,CCCCC are of type C.

for this the output should look like
AAAAA AAAAA P
BBBBB AAAAA S
CCCCC AAAAA S

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 Nov 16, 2005 9:55 am    Post subject: Reply with quote

dhulipalla,

Try this

Code:

SELECT A.PCODE                                           
      ,B.PCODE                                           
  FROM Table  A                                             
      ,(SELECT SCODE,PCODE FROM Table WHERE TYPE = 'P') B   
 WHERE A.SCODE = B.SCODE                                 
;


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
dhulipalla
Beginner


Joined: 24 Aug 2004
Posts: 21
Topics: 6

PostPosted: Wed Nov 16, 2005 6:46 pm    Post subject: Reply with quote

Kolusu,

That's working fine..Thanks..
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