Hello, everyone!
Here's are the basics:
1. The query looks at all positions that are active and haven't been filled.
2. It then has to look at every single position and determine three things:
Does the person running the query (via an ASP page) have certain rights?
a. Recruit rights
b. Enlist rights
c. Take rights
This works fine for 100 or less positions. But I recently added 5000 positions to the table, and of course the query takes FOREVER to run because it's looping upon itself (a big NO NO).
I've indexed the table and it helped a bit, but I think a view or stored procedure might be in order. Unfortunately, I know little about either, and as you can tell my querying skills are lacking in the sophistication department.
Also, none of the fields can be combined into a single field, hence the Ors in each section. A person could have Recruit/Enlist/Take rights based upon at least 5 fields per right.
Thoughts?
=============== ======== CODE =============== ===========
sSQL = "SELECT * FROM positions"
sSQL = sSQL & " WHERE active=1"
sSQL = sSQL & " AND filled_date is NULL"
sSQL = sSQL & " AND filled_by is NULL"
Set conn = OpenConn()
Set rsPositions = conn.Execute(sS QL)
Dim j
j = 0
%>
<html>
<head>
</head>
<body>
<div class="mc">
<table border="0" width="100%">
<%
Do while not rsPositions.EOF
nPositionID = rsPositions("po sition_id")
sTitle = rsPositions("ti tle")
sDescription = rsPositions("de scription")
dTargetHireDate = FormatDateTime( rsPositions("ta rget_hire_date" ),2)
// Recruit Link SQL
if inStr(rsPositio ns("recruit_by_ security"),cSec urity) > 0 or _
inStr(rsPositio ns("recruit_by_ member"),cUserI D) > 0 or _
inStr(rsPositio ns("recruit_by_ state"),cState) > 0 or _
inStr(rsPositio ns("recruit_by_ county"),cCount y) > 0 or _
inStr(rsPositio ns("recruit_by_ wardprecinct"), cWardPrecinct) > 0 or _
inStr(rsPositio ns("recruit_by_ zip"),cZip) > 0 then
ShowRecruitLink = "yes"
else
ShowRecruitLink = ""
end if
// Controlled Enlist Link SQL
Set rsEnlist = conn.execute("S ELECT enlist_by_membe r_control FROM action_recruitm ent_positions WHERE position_id = " & rsPositions(0))
if inStr(rsEnlist( 0),cUserID) > 0 then
ShowEnlistLink = "yes"
else
ShowEnlistLink = ""
end if
// Self Enlist Link SQL
if inStr(rsPositio ns("enlist_by_s ecurity"),cSecu rity) > 0 or _
inStr(rsPositio ns("enlist_by_m ember"),cUserID ) > 0 or _
rsPositions("en list_by_state") = cState or _
rsPositions("en list_by_county" ) = cCounty or _
rsPositions("en list_by_wardpre cinct") = cWardPrecinct or _
inStr(rsPositio ns("enlist_by_z ip"),cZip) > 0 then
ShowSelfEnlistL ink = "yes"
else
ShowSelfEnlistL ink = ""
end if
if ShowRecruitLink = "yes" or ShowEnlistLink = "yes" or ShowSelfEnlistL ink = "yes" then
%>
<tr>
<td class="mc">
<b><%=sTitle% ></b><br />
<%=sDescription %><br />
Target Hire Date: <%=dTargetHireD ate%> <br />
</td>
<td class="mc" align="right" valign="top" align="center">
<%if ShowRecruitLink = "yes" then %>
<a href="#" onclick="window .open('../action_recruitm ent_invite.asp? action=recruit& position_id=<%= nPositionID%>&i nvitee_id=<%=cU serID%>', 'recruit', 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');">R ecruit</a>
<%end if %>
<%if ShowEnlistLink = "yes" then %>
<br /><a href="#" onclick="window .open('../action_recruitm ent_invite.asp? action=enlist&p osition_id=<%=n PositionID%>&in vitee_id=<%=cUs erID%>', 'recruit', 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');">E nlist</a>
<%end if %>
<%if (ShowSelfEnlist Link = "yes" or ShowSelfEnlistL inkByGeoPol = "yes") then
j = j + 1
%>
<form name="form<%=j% >" action="availab le_positions.as p">
<input type="hidden" name="position_ id" value="<%=nPosi tionID%>" />
<input type="hidden" name="filled_da te" value="<%=date( )%>" />
<input type="hidden" name="filled_by " value="<%=cUser ID%>" />
<input type="hidden" name="action" value="takePosi tion" />
<br /><a href="#" onclick="submit Status(document .form<%=j%>);"> Take</a>
</form>
<%end if %>
</td>
</tr>
<%
end if
rsPositions.Mov eNext
Loop
%>
</table>
</div>
</body>
</html>
<%
rsPositions.Clo se
set rsPositions = Nothing
conn.Close
set conn = Nothing
%>
=============== ======== CODE =============== ===========
Here's are the basics:
1. The query looks at all positions that are active and haven't been filled.
2. It then has to look at every single position and determine three things:
Does the person running the query (via an ASP page) have certain rights?
a. Recruit rights
b. Enlist rights
c. Take rights
This works fine for 100 or less positions. But I recently added 5000 positions to the table, and of course the query takes FOREVER to run because it's looping upon itself (a big NO NO).
I've indexed the table and it helped a bit, but I think a view or stored procedure might be in order. Unfortunately, I know little about either, and as you can tell my querying skills are lacking in the sophistication department.
Also, none of the fields can be combined into a single field, hence the Ors in each section. A person could have Recruit/Enlist/Take rights based upon at least 5 fields per right.
Thoughts?
=============== ======== CODE =============== ===========
sSQL = "SELECT * FROM positions"
sSQL = sSQL & " WHERE active=1"
sSQL = sSQL & " AND filled_date is NULL"
sSQL = sSQL & " AND filled_by is NULL"
Set conn = OpenConn()
Set rsPositions = conn.Execute(sS QL)
Dim j
j = 0
%>
<html>
<head>
</head>
<body>
<div class="mc">
<table border="0" width="100%">
<%
Do while not rsPositions.EOF
nPositionID = rsPositions("po sition_id")
sTitle = rsPositions("ti tle")
sDescription = rsPositions("de scription")
dTargetHireDate = FormatDateTime( rsPositions("ta rget_hire_date" ),2)
// Recruit Link SQL
if inStr(rsPositio ns("recruit_by_ security"),cSec urity) > 0 or _
inStr(rsPositio ns("recruit_by_ member"),cUserI D) > 0 or _
inStr(rsPositio ns("recruit_by_ state"),cState) > 0 or _
inStr(rsPositio ns("recruit_by_ county"),cCount y) > 0 or _
inStr(rsPositio ns("recruit_by_ wardprecinct"), cWardPrecinct) > 0 or _
inStr(rsPositio ns("recruit_by_ zip"),cZip) > 0 then
ShowRecruitLink = "yes"
else
ShowRecruitLink = ""
end if
// Controlled Enlist Link SQL
Set rsEnlist = conn.execute("S ELECT enlist_by_membe r_control FROM action_recruitm ent_positions WHERE position_id = " & rsPositions(0))
if inStr(rsEnlist( 0),cUserID) > 0 then
ShowEnlistLink = "yes"
else
ShowEnlistLink = ""
end if
// Self Enlist Link SQL
if inStr(rsPositio ns("enlist_by_s ecurity"),cSecu rity) > 0 or _
inStr(rsPositio ns("enlist_by_m ember"),cUserID ) > 0 or _
rsPositions("en list_by_state") = cState or _
rsPositions("en list_by_county" ) = cCounty or _
rsPositions("en list_by_wardpre cinct") = cWardPrecinct or _
inStr(rsPositio ns("enlist_by_z ip"),cZip) > 0 then
ShowSelfEnlistL ink = "yes"
else
ShowSelfEnlistL ink = ""
end if
if ShowRecruitLink = "yes" or ShowEnlistLink = "yes" or ShowSelfEnlistL ink = "yes" then
%>
<tr>
<td class="mc">
<b><%=sTitle% ></b><br />
<%=sDescription %><br />
Target Hire Date: <%=dTargetHireD ate%> <br />
</td>
<td class="mc" align="right" valign="top" align="center">
<%if ShowRecruitLink = "yes" then %>
<a href="#" onclick="window .open('../action_recruitm ent_invite.asp? action=recruit& position_id=<%= nPositionID%>&i nvitee_id=<%=cU serID%>', 'recruit', 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');">R ecruit</a>
<%end if %>
<%if ShowEnlistLink = "yes" then %>
<br /><a href="#" onclick="window .open('../action_recruitm ent_invite.asp? action=enlist&p osition_id=<%=n PositionID%>&in vitee_id=<%=cUs erID%>', 'recruit', 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');">E nlist</a>
<%end if %>
<%if (ShowSelfEnlist Link = "yes" or ShowSelfEnlistL inkByGeoPol = "yes") then
j = j + 1
%>
<form name="form<%=j% >" action="availab le_positions.as p">
<input type="hidden" name="position_ id" value="<%=nPosi tionID%>" />
<input type="hidden" name="filled_da te" value="<%=date( )%>" />
<input type="hidden" name="filled_by " value="<%=cUser ID%>" />
<input type="hidden" name="action" value="takePosi tion" />
<br /><a href="#" onclick="submit Status(document .form<%=j%>);"> Take</a>
</form>
<%end if %>
</td>
</tr>
<%
end if
rsPositions.Mov eNext
Loop
%>
</table>
</div>
</body>
</html>
<%
rsPositions.Clo se
set rsPositions = Nothing
conn.Close
set conn = Nothing
%>
=============== ======== CODE =============== ===========
Comment