Click here to Skip to main content
15,848,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

for banking application , i need a query which retrive all the matched column data from bottom to top

i have tho tables

in table 1 i have


Group_Id    Group_Name            Primary_Group_Id
1            assets                    null  
2            liabilities               1
3            fixed                     2
4            expenses                  3
...


table 2
ID   Group_Id
948   3
955   2 


my requirement is , i will pass the ID=948 and i need to get the total HIERARCHY data from the bottom to top of
table 1

result: i want the following as output

ID   Group_Id  Group_Name  Primary_Group_Id  Group_Name    Group_Id  Group_Name
948  3         Fixed           2             liabilities    1        assets
Posted
Updated 5-Oct-12 2:05am
v2
Comments
Aarti Meswania 5-Oct-12 7:09am    
you want output in single row?
or like this
id grp_id grp_nm
948 3 fixed
948 2 liabilities
948 1 assets
sk. maqdoom ali 5-Oct-12 7:23am    
yes, i want output like this
id grp_id grp_nm
948 3 fixed
948 2 liabilities
948 1 assets

1 solution

See the following tip :
Building hierarchy using Recursive CTE[^]

It should give you a start.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900