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
 General SQL Server Forums
 New to SQL Server Programming
 Get Child Value from a single table structure

Author  Topic 

BigMeat
Yak Posting Veteran

56 Posts

Posted - 2008-06-13 : 12:51:23
Hi

I have a single table which holds a hierarchical a structure. I would like to get all the child ID's from one Stored Proc call. For example I give it an ID in the structure and I would like to give me all the child records that exist to the lowest level for each category found

My table structure is
[SvcID] [varchar](30) NOT NULL,
[Ser_SvcID] [varchar](30) NULL,
[SvcDesc] [varchar](100) NOT NULL

I know where the root of the hierarchy is because Ser_SvcID will be null. Im not sure how to do this in one stored procedure call

Hope the above makes sense

Many thanks in advance


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-13 : 12:54:36
Are you using SQL 2005? if yes you can use recursive CTE approach;-

http://msdn.microsoft.com/en-us/library/ms186243.aspx

and if you're using SQL 200 you can use this method

http://support.microsoft.com/kb/248915
Go to Top of Page

BigMeat
Yak Posting Veteran

56 Posts

Posted - 2008-06-13 : 15:50:00
Thanks visakh16, that worked a treat

Go to Top of Page
   

- Advertisement -