Display Managers and Employees Database

J

JP SIngh

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?
 
J

JP SIngh

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.
 
J

Jeff Cochran

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/[email protected]

Jeff
 
A

Al

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..!
 
J

JP SIngh

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\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
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top