Stored Procedure Recursion
Home :: SQL Server :: Recursion
Here are two SQL server stored procedures that demonstrate how to handle recursion in hierarchical data The first procedure (sp_ForumThreads) is a ‘wrapper’ that creates a temp table (exists in memory only because it has a # before its name) which is filled by the second procedure (sp_RecurseForum).
The principle applies to anywhere you have a 'tree' in your data. Microsoft have an example on their site that you might also find useful at Zen of Recursion which I referenced but, believe me, the code below offers the complete solution (having taken a couple of days to arrive at!).
here's a working forum based on this code
You can call the procedure from an Active Server page like this…
<% Dim
RS_Threads SET RS_Threads = Server.CreateObject(
"ADODB.Recordset" ) Dim cmdThreads Set cmdThreads =
Server.CreateObject("ADODB.Command") With
cmdThreads
The rest of this page is hidden, you must be a member to view itTo become a member and get immediate access to the course please join here Free!
Next >> SQLOLEDB
|
|