Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Sql server 2000

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-02-23 : 08:19:54
Tirupati Parida writes "I have two tables. Contacts and AssoContacts tables.

Contacts Table - Contact_Id int, Con_Desc varchar(50)
AssoContacts Table - Contact_Id int, AssoContact_Id int

Contacts table is the master table having unique records for contacts and their description. AssoContact is the child table having Contact_Id and its associted Contact_Id. AssoContact Table having records with One many relationship. For Example :

Contact_Id AssoContact_Id
1 2
1 3
2 4
3 5
3 6
4 2
5 8

I would like to pass the contact_Id as the parameter to fetch all the associted contact details recursively. For example if passed 1 as parameter then the out put will be 2,3,4,5,6,8

That is it should fetch records recursively for all the associted contacts. How to solve it ?"

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2005-02-23 : 12:50:59
I am a little confused by the "recursive" you are passing in 1 which is associated with results 2, 3 could you explain what you mean by recursive? do you mean

1: 2, 3 where 2 gets 4 and 3 gets 5, 6 then those results are searched 5 gets 8. so your distinct results set is 2, 3, 4, 5, 6, 8

You can do anything at www.zombo.com
Go to Top of Page

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2005-02-23 : 12:51:58
If so look at creating a while loop with an insert into a temp table the select the distinct results from the temp table back to the user.

You can do anything at www.zombo.com
Go to Top of Page
   

- Advertisement -