View previous topic :: View next topic |
Author |
Message |
dhulipalla Beginner
Joined: 24 Aug 2004 Posts: 21 Topics: 6
|
Posted: Tue Nov 15, 2005 9:54 pm Post subject: Populate Primary code to secondary code rows using SQL |
|
|
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 |
|
 |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Tue Nov 15, 2005 11:18 pm Post subject: sql query |
|
|
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 |
|
 |
dhulipalla Beginner
Joined: 24 Aug 2004 Posts: 21 Topics: 6
|
Posted: Tue Nov 15, 2005 11:50 pm Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Nov 16, 2005 5:52 am Post subject: |
|
|
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 |
|
 |
dhulipalla Beginner
Joined: 24 Aug 2004 Posts: 21 Topics: 6
|
Posted: Wed Nov 16, 2005 9:08 am Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Nov 16, 2005 9:25 am Post subject: |
|
|
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 |
|
 |
dhulipalla Beginner
Joined: 24 Aug 2004 Posts: 21 Topics: 6
|
Posted: Wed Nov 16, 2005 9:40 am Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Nov 16, 2005 9:55 am Post subject: |
|
|
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 |
|
 |
dhulipalla Beginner
Joined: 24 Aug 2004 Posts: 21 Topics: 6
|
Posted: Wed Nov 16, 2005 6:46 pm Post subject: |
|
|
Kolusu,
That's working fine..Thanks.. |
|
Back to top |
|
 |
|
|