ReportingAnalyst
MIS
Is it possible to call a recursive program on demand?
For instance, I have a function -
getSubordinates(ManagerID, Counter)
within which I call the above function to get the nested subordinates.
If a subordinate is a manager, I add a hyperlink to the manager name other just display his name. That hyperlink has a onclick event to drill down to see the further nested hierarchy.
My question here is can I call the function which in turn builds the SQL query to get the nested subordinates recordset only when I were to click on the link...
My GetSubordinates(ManagerID, Counter) function is:
Code takes 33 seconds for the top most guy. So wondering what other ways I can use to get this faster. I have optimized my SQL queries and it is down from 54 to 33 seconds. But would like to improve the speed more.
Secondly saw in another post that if I were to to Recordset.Filter, it could make my execution faster. How can I apply the filter in the recordset other than the where clause in the SQL query?
Thanks.
For instance, I have a function -
getSubordinates(ManagerID, Counter)
within which I call the above function to get the nested subordinates.
If a subordinate is a manager, I add a hyperlink to the manager name other just display his name. That hyperlink has a onclick event to drill down to see the further nested hierarchy.
My question here is can I call the function which in turn builds the SQL query to get the nested subordinates recordset only when I were to click on the link...
My GetSubordinates(ManagerID, Counter) function is:
Code:
Function GetSubordinates(managerID, Counter)
'Creating a log file to detect errors:
'If Not(IsObject(objFSO)) Then
' Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'End If
'Dim objFSO, objLogFile, strLogFilePath
'Const LOG_FILE_NAME="GetSubordinate.txt"
'strLogFilePath = Server.MapPath(LOG_FILE_NAME)
'Set objFile = objFSO.OpenTextFile(strLogFilePath, 8) 'ForAppending
'objFile.WriteLine("manager: " & managerID & " " & Now())
'objFile.Close
sub_Emp_Source = "SELECT AMP_AllMySubordinates_Postings.Member_Manager, " & _
"AMP_AllMySubordinates_Postings.Member_Subordinate, " & _
"AMP_AllMySubordinates_Postings.Owner_DateOfPost, " & _
"Employee.EmpID, " & _
"Employee.FirstName + ' ' + Employee.LastName AS Emp_Name, " & _
"Employee.LastName " & _
"FROM AMP_AllMySubordinates_Postings " & _
"INNER JOIN Employee ON " & _
"AMP_AllMySubordinates_Postings.Member_Subordinate = Employee.UniqueIdentifier " & _
"WHERE AMP_AllMySubordinates_Postings.Member_Manager = " & managerID & " " & _
"AND AMP_AllMySubordinates_Postings.Owner_Payee = " & strUI & " " & _
"AND AMP_AllMySubordinates_Postings.Owner_DateOfPost In " & _
"(Select MAX(AMP_AllMySubordinates_Postings.Owner_DateOfPos t) FROM Amp_AllMySubordinates_Postings WHERE owner_payee = " & strUI & ") " & _
"ORDER BY Employee.LastName; "
Dim rs2
set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.open sub_Emp_Source, Conn
Dim aSubordinates
If not rs2.EOF then
aSubordinates = rs2.GetRows()
'Close Recordset to use the new array with the 2 columns data
rs2.Close()
set rs2 = Nothing
'Declare Constants for the above SQL columns for better readability
'Use these Constants instead of referring to the array numeric indexes
Const c_Manager = 0
Const c_Subordinate = 1
Const c_PostDate = 2
Const c_EmpID = 3
Const c_EmpName = 4
'Ubound(MyArray,1) 'Returns the Number of Columns
'Ubound(MyArray,2) 'Returns the Number of Rows
Dim iRowLoop
For iRowLoop = 0 to UBound(aSubordinates, 2)
Dim uniqueID
'Changed this from managerid to subordinate id because we want to see the subordinates for the member_subordinate
uniqueID = aSubordinates(c_Subordinate, iRowLoop)
Dim ManagerOrNot
ManagerOrNot = IsManager(uniqueID)
Dim indent
indent = "**"
If ManagerOrNot = True then
'Is a manager
%>
<li>
<input type="radio" name="empid" id="empid<%=aSubordinates(c_EmpID,iRowLoop)%>" value="<%=aSubordinates(c_EmpID,iRowLoop)%>" onClick="showReports(this.value)">
<a href="#" class="a_style" onclick="s_Hide('<%=aSubordinates(c_Subordinate, iRowLoop)%>'); return false;"><%=aSubordinates(c_EmpName,iRowLoop)%></a><font size=1>*(<%=aSubordinates(c_EmpID,iRowLoop)%>)</font>
<ul id="<%=aSubordinates(c_Subordinate, iRowLoop)%>" style="display: none">
<%
Counter = Counter + 1
[b] 'can i call this on demand when there the users click on the link
Call GetSubordinates(uniqueID, Counter)
[/b]
Counter = Counter - 1
%>
</ul>
</li>
<%
Else
%>
<li>
<input type="radio" name="empid" id="empid<%=aSubordinates(c_EmpID,iRowLoop)%>" value="<%=aSubordinates(c_EmpID,iRowLoop)%>" onClick="showReports(this.value)">
<%=aSubordinates(c_EmpName,iRowLoop)%>*<font size=1>(<%=aSubordinates(c_EmpID,iRowLoop)%>)</font>
</li>
<%
End if 'ManagerOrNot = true or false
Next 'iRowLoop
%>
<%
End If 'rs2.EOF
End Function
Code takes 33 seconds for the top most guy. So wondering what other ways I can use to get this faster. I have optimized my SQL queries and it is down from 54 to 33 seconds. But would like to improve the speed more.
Secondly saw in another post that if I were to to Recordset.Filter, it could make my execution faster. How can I apply the filter in the recordset other than the where clause in the SQL query?
Thanks.