Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Reporting a menu structure using a recursive UDF Expand / Collapse
Author
Message
Posted Tuesday, September 6, 2005 10:34 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, August 1, 2011 2:05 PM
Points: 32, Visits: 47
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/slasham/reportingamenustructureusingarecursiveudf.asp


Post #217493
Posted Tuesday, October 11, 2005 9:38 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 30, 2014 10:08 PM
Points: 1,038, Visits: 444

This seems needlessly complex - I just made a UDF that recursively calls itself with more than 1 parameter in my temp database and it works fine?

Example (and it's a silly one but it does work - it's 1am here!)

use TempDB
GO
create function recurse(
@p1 int,
@p2 varchar(10)
)
returns varchar(8000)
AS
begin
declare @result varchar(8000)
if @p1 = 0
  set @result = @p2
else
  set @result = dbo.recurse(@p1 - 1, @p2 + '.' + cast(@p1 as char(1)))
return @result
end
GO
print dbo.recurse(5, 'X')

 

I can see the benefit of the idea for some reporting purposes where you cannot have the tool work out how the hierarchy relates in client-side code, but if the entire hierarchy is being sent back to the client, you could also just send back the table and let the client sort out the display as well...  Depends on the circumstances I suppose.

If someone is to implement in their DB/software, try rewriting without the messy string splitting for parameter passing - I don't see why it shouldn't work...

Cheers  




Post #227983
Posted Tuesday, October 11, 2005 4:04 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, August 1, 2011 2:05 PM
Points: 32, Visits: 47
I'll have to tweek my own code as for some reason I was sure I could only have one parameter.  Thanks for this.


Post #228135
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse