Re: Recursive function help

From: JP SIngh (none_at_none.com)
Date: 07/28/04


Date: Wed, 28 Jul 2004 16:11:02 +0100

Hi Ray

You are correct I am looking to create a tree like structure for all
employees who report to thier manager.

I appreciate any help with a bit of code which can do something like that.

I want the tree to look like this

Dean
       Karol
                Ray
                Chuck
                Bradley
       Gary
               Robert
               Tina

Can you help. We have been trying to do this for ages but no luck

thanks a lot

"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:%23bEfhBLdEHA.2696@TK2MSFTNGP09.phx.gbl...
> Not that this is an answer to your question, but are you trying to just
> create a list of employees and who they report to or something along those
> lines? You don't need to execute multiple queries for this. You could do
> something like this:
>
>
>
> Table: Emps:
> EmpID EmpName ReportsTo
> 1 Ray 2
> 2 Karol 3
> 3 Dean 0
> 4 Gary 3
> 5 Robert 4
> 6 Tina 4
> 7 Chuck 2
> 8 Bradley 2
>
>
> Query:
> select a.empid as [ID], a.empname as [Emp], b.empname as [Boss] from emps
a
> left outer join emps b on a.reportsto=b.empid
>
> Results:
> ID Emp Boss
> -- ------ ------
> 1 Ray Karol
> 2 Karol Dean
> 3 Dean
> 4 Gary Dean
> 5 Robert Gary
> 6 Tina Gary
> 7 Chuck Karol
> 8 Brian Karol
>
> Ray at work
>
>
>
>
>
> "JP SIngh" <none@none.com> wrote in message
> news:ukFJKYJdEHA.2752@TK2MSFTNGP12.phx.gbl...
> > Hi All
> >
> > I am trying to write a recursive function to list the managers and his
> > employees in a tree like sctructure
> >
> > Manager 1
> > Emp1
> > Emp1.1
> > Emp 1.2
> > Emp 2
> > Emp 3
> > Emp 3.1
> > Emp 3.2
> >
> > Have written the following code but don't seems to be getting anywhere
> >
> > It gives me this error
> >
> > Microsoft VBScript runtime error '800a01fb'
> > An exception occurred: 'dbRS.Open'
> > /admin/man.asp, line 20
> > Someone please help
> >
> > Regards
> >
> > Jas
> >
> > <%
> > set conn = Server.Createobject("ADODB.Connection")
> > conn.Provider = "Microsoft.Jet.OLEDB.4.0"
> > conn.Open "D:\Applications\Holidays12004\Includes\holidays.mdb"
> > Getparents()
> >
> > Function GetParents()
> > Set dbRS = Server.CreateObject("ADODB.Recordset")
> > ' ADO code to load all the posts with a null parent
> > dbRS.Open "SELECT * FROM empprofile order by managername", conn
> > Do While Not dbRS.EOF
> > GetReplies(dbRS.Fields("empname"))
> > dbRS.MoveNext
> > Loop
> > End Function
> >
> > Function GetReplies(parentID)
> > Set dbRS = Server.CreateObject("ADODB.Recordset")
> > dbRS.Open "SELECT * FROM empprofile WHERE managername = '" &
parentid
> > &
> > "'", conn
> > Do While Not dbRS.EOF
> > Response.write "mangername = " & dbRS.Fields("managername") &
"
> > empname = " & dbRS.Fields("empname") & "<br>"
> > ' <-- Your recursive call. Walks down each tree branch until
> > ' it hits the last reply in a tree (dbRS returns no rows), then backs
> > out.
> > GetReplies(dbRS.Fields("empname"))
> > dbRS.MoveNext
> > Loop
> > End Function
> > %>
> >
> >
>
>



Relevant Pages

  • Re: Recursive function help
    ... create a list of employees and who they report to or something along those ... Ray Karol ... Karol Dean ...
    (microsoft.public.inetserver.asp.general)
  • Idiot Christian Richie, Dum-Dum Elkins, and Kozels favorite Pres
    ... Investigators from the Interior Department's inspector general's ... office said more than a dozen employees, ... of the oil royalty program, accepted gifts including ski trips, sports ... The report contains fresh allegations about the culture and practices ...
    (misc.transport.road)
  • Re: What would you do?
    ... information to those persons as per your company's policies. ... >victimized by viruses, hackers or rogue employees. ... But this affair can have ... Any other employee - and a brief report of my findings ...
    (microsoft.public.exchange.admin)
  • Re: Your DAC Report And Your Rights
    ... Tony's given you the scoop on DAC, as it used to be called. ... Anyway, they didn't report anything to DAC, nobody is required to use ... requirements that employees must be notified so many days in advance before ... " USIS, as a nationwide specialty consumer reporting agency, is subject to ...
    (misc.transport.trucking)