question

omprakashsahlive avatar image
omprakashsahlive asked

find nested chield through parent in sql

i have a table 'MEMBERSHIP' Which contain follwing field (MEMBER_CODE,MEMBER_NAME,RANK_POS,INTRODUCER_CODE} NOW I HAVE TO CHAIN MEMBER LIKE A INTRODUCE BY B (A-MEMBER_CODE,B WILL INTRODUCER) C INTRODUCE BY A D INTRODUCE BY C SO I I HAVE TO FIND OUT B CHAIN IT WILL BE DISPLAY LIKE THIS A,C,D INFORMATION
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
GPO avatar image
GPO answered
There's a good explanation of how a recursive CTE should do what you want it to do [here][1] [1]: http://msdn.microsoft.com/en-au/library/ms186243(v=sql.105).aspx I suppose the corollary questions will be: How many levels deep will the chain of members and introducers go? How many members all told, do you need your system to be able to accommodate. If you have a million members and there are 50 levels of introduction, the above solution might not be an appropriate option from a performance point of view.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.