| Author |
Display Managers and Employees Database
|
|
| JP SIngh 2004-07-27, 8:55 am |
| Hi All
I am in a very tricky situation wonder if you anyone can help.
We have a table where we store employee information. One of the fields in
the table stores the manager number which is the employee number of the
users manager. Sample data is below
EmpNo Name ManagerNo
2211 Peter 9900
8899 James 9900
9900 Mel 9111
9901 Ian 9111
9111 Simon 9111
I want to able to display all the employees who report to a certain manager
and also all the employees who report to them
Something like
Simon
Ian
Mel
Peter
James
I am sure this can be done but I don't know how to do it recursively. Can
help guys?
| |
| Curt_C [MVP] 2004-07-27, 8:55 am |
| recursive looping.
It's your basic tree building. I have a sample or two on my site but start
with:
www.darkfalz.com/1056
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"JP SIngh" <none@none.com> wrote in message
news:edws3Q9cEHA.2236@TK2MSFTNGP10.phx.gbl...
> Hi All
>
> I am in a very tricky situation wonder if you anyone can help.
>
> We have a table where we store employee information. One of the fields in
> the table stores the manager number which is the employee number of the
> users manager. Sample data is below
>
> EmpNo Name ManagerNo
> 2211 Peter 9900
> 8899 James 9900
> 9900 Mel 9111
> 9901 Ian 9111
> 9111 Simon 9111
>
> I want to able to display all the employees who report to a certain
manager
> and also all the employees who report to them
>
> Something like
>
> Simon
> Ian
> Mel
> Peter
> James
>
> I am sure this can be done but I don't know how to do it recursively. Can
> help guys?
>
>
| |
| JP SIngh 2004-07-27, 3:55 pm |
| Thanks Curt but we don't store the level numbers as in your example of
forums so it is slightly difficult to modify your code to get to our
solution.
WOuld you or anyone else be kind enough to write some code to crack this. We
have been trying to do this for the last 3 months without success.
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%23zP4rY9cEHA.3896@TK2MSFTNGP10.phx.gbl...
> recursive looping.
> It's your basic tree building. I have a sample or two on my site but start
> with:
> www.darkfalz.com/1056
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
> "JP SIngh" <none@none.com> wrote in message
> news:edws3Q9cEHA.2236@TK2MSFTNGP10.phx.gbl...
in[color=darkred]
> manager
Can[color=darkred]
>
>
| |
| Curt_C [MVP] 2004-07-27, 3:55 pm |
| The idea is the same, you have a function that passes in a parameter. This
function calls itself from within the loop.
Asking people to write it for you isn't the best way to go about it, trying
and then posting when you get stuck is preferred.
So some searching on Recusion or Recursive calls, and you should find more
on this.
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
| |
| Jeff Cochran 2004-07-27, 3:55 pm |
| On Tue, 27 Jul 2004 13:21:21 +0100, "JP SIngh" <none@none.com> wrote:
>Hi All
>
>I am in a very tricky situation wonder if you anyone can help.
>
>We have a table where we store employee information. One of the fields in
>the table stores the manager number which is the employee number of the
>users manager. Sample data is below
>
>EmpNo Name ManagerNo
>2211 Peter 9900
>8899 James 9900
>9900 Mel 9111
>9901 Ian 9111
>9111 Simon 9111
>
>I want to able to display all the employees who report to a certain manager
>and also all the employees who report to them
>
>Something like
>
>Simon
> Ian
> Mel
> Peter
> James
>
>I am sure this can be done but I don't know how to do it recursively. Can
>help guys?
Start by telling us what database you use. Also, where are you having
the problems, retrieving the data or displaying it?
Besides, a quick Google of the groups probably finds your answer here:
http://groups.google.com/groups?hl=...ting.google.com
Jeff
| |
|
| Group it as followed.
Dim iOldManagerNo as integer
Dim oEmpRs as RecordSet
Set oEmpRs = oConnection.OpenRecordSet("SELECT * FROM From Employee Order By
ManagerNo")
IF not oEmpRs.EOF
'- First Group.
Print ManagerNo Group
Do While oEmpRs.EOF
if oEmpRs!ManagerNo <> iOldManagerNo then
iOldManagerNo = oEmpRs!ManagerNo
Print ManagerNo Group
End if
Print EmpNo, Name
Loop
End if
oEmpRs.Close
Set oEmpRs = Nothing
Good Luck..!
"JP SIngh" <none@none.com> wrote in message
news:edws3Q9cEHA.2236@TK2MSFTNGP10.phx.gbl...
> Hi All
>
> I am in a very tricky situation wonder if you anyone can help.
>
> We have a table where we store employee information. One of the fields in
> the table stores the manager number which is the employee number of the
> users manager. Sample data is below
>
> EmpNo Name ManagerNo
> 2211 Peter 9900
> 8899 James 9900
> 9900 Mel 9111
> 9901 Ian 9111
> 9111 Simon 9111
>
> I want to able to display all the employees who report to a certain
manager
> and also all the employees who report to them
>
> Something like
>
> Simon
> Ian
> Mel
> Peter
> James
>
> I am sure this can be done but I don't know how to do it recursively. Can
> help guys?
>
>
| |
| JP SIngh 2004-07-28, 3:55 pm |
| Guys
I have tried something but not sure if this is right.
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\h
olidays.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
%>
"Al" <jodizco@msn.com> wrote in message
news:OETS9BAdEHA.712@TK2MSFTNGP09.phx.gbl...
> Group it as followed.
>
> Dim iOldManagerNo as integer
> Dim oEmpRs as RecordSet
>
> Set oEmpRs = oConnection.OpenRecordSet("SELECT * FROM From Employee Order
By
> ManagerNo")
>
>
> IF not oEmpRs.EOF
>
> '- First Group.
> Print ManagerNo Group
>
> Do While oEmpRs.EOF
>
> if oEmpRs!ManagerNo <> iOldManagerNo then
> iOldManagerNo = oEmpRs!ManagerNo
> Print ManagerNo Group
> End if
> Print EmpNo, Name
>
> Loop
>
> End if
> oEmpRs.Close
> Set oEmpRs = Nothing
>
> Good Luck..!
>
> "JP SIngh" <none@none.com> wrote in message
> news:edws3Q9cEHA.2236@TK2MSFTNGP10.phx.gbl...
in[color=darkred]
> manager
Can[color=darkred]
>
>
|
|
|
|