PDA

View Full Version : random assigment/update


mcsadapted
12-22-2002, 05:18 PM
I need to be able to more or less randomly assign customers to a new sales reps when their cuurent sales rep leaves the company. For example, a ex-saleman's two-hundred customers need to be more or less automatically distributed more or less evenly among 20 remaining reps. We are sort of new to all this...any help would be greatly appreciated.

oracleguy
12-22-2002, 08:15 PM
Wheres the information on the customers and the remaining sales reps stored? In a database?

mcsadapted
12-22-2002, 08:32 PM
Thanks for the reply. The 30 or so salesreps are in an Access 2000 table (just three fields: name, ID, Active/Inactive) as are the customers (currently about three thousand.) Each customer has a salesrep ID field among thirty or so other fields linking to three or four other tables. The idea is that some sort of SQL or ASP process would with minmal user input reassign the "orphaned" customers evenly among the active salesreps...

oracleguy
12-23-2002, 03:49 AM
Oh, okay... lemme cook that up for ya :)

oracleguy
12-23-2002, 04:23 AM
Okay it all works... all you have to do is change the fields, table names and the database connection information.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Replace and Reassign</title>
</head>

<body style="font-family: Verdana; font-size: 10pt; color: #000000;">
<form action="" method="post">
<p>Enter name of the sales rep that you wish to re-assign: <input type="text" size="40" name="sales" /></p>
<p><input type="submit" value="Re-assign." name="submit" /></p>
</form>
<%
If Request.Form("sales")<>"" Then
Dim strConnection, intCustomers, intRepID
Set cSQL=Server.CreateObject("ADODB.Connection")
strConnection = "Driver=MySQL;server=GEMINI;user id=;password=;database=test1;"

cSQL.ConnectionString=strConnection
cSQL.Open

Set reps=cSQL.Execute("SELECT * FROM salesreps WHERE name='"&Request.Form("sales")&"';")
If reps.EOF Then
%>
<p style="color: #FF0000;"><b>ERROR : </b>There was no sales rep with that name in the database.</p>
<%
Else
intRepID=reps("salesrepID")

Set reps=cSQL.Execute("SELECT * FROM salesreps WHERE status='Active';")
intCustomers=0
Set cmrs=cSQL.Execute("SELECT * FROM customers WHERE salesrepID='"&intRepID&"';")
Do While Not cmrs.EOF
If reps.EOF Then reps.MoveFirst

cSQL.Execute "UPDATE customers SET salesrepID='" & reps("salesrepID") & "' WHERE fullname='" & cmrs("fullname") & "'"
intCustomers=intCustomers+1
cmrs.MoveNext
reps.MoveNext
Loop
%>
<p><b>Update completed. <%= intCustomers %> customers were re-assigned.</b></p>
<%
End If
End If
%>

</body>
</html>


It should all work.

mcsadapted
12-23-2002, 02:31 PM
Wow! I will try to put this into action as soon as I can... I really appreciate your knowledge time and effort. Thanks!