Stored Procedure Recursion
Skip Navigation Links.

Stored Procedure Recursion

Skip Navigation LinksHome :: 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 it

To become a member and get immediate access to the course please join here Free!

Already Enrolled? please click here to Login

Next >> SQLOLEDB
top of page
all content ©1996/2012 BennySutton.com
all images © their respective owners This site uses Thumbshots previews