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
 recursive loop

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2012-08-22 : 09:15:04
Hi i need a query that loops through all children in the table below, not sure how i can do this, inside the loop i will be stroing the Id into a temp table which i know how todo, just need help with the recursive loop

Id ParentId
1 0
2 0
3 1
4 3
5 4

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-22 : 09:19:40
check out this http://msdn.microsoft.com/en-us/library/ms186243%28v=sql.105%29.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-22 : 10:44:55
recursive cte should be what you'll be using for this

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -