This post has been edited by moojoo: 08 November 2006 - 02:59 PM
SQL Insert Help Pls
Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.
SQL Insert Help Pls
#41
Posted 08 November 2006 - 09:26 AM
#42
Posted 08 November 2006 - 10:31 AM
do until c = numEmployees
c = c + 1
Randomize
max=75
min=1
freebox = empName & " " & empName2 & "<br />" & theCurrentDate
table = "<table><thead><th>B</th><th>I</th><th>N</th><th>G</th><th>O</th></thead>"
table = table & newrow(1) & newrow(2)
table = table & "<tr><td>" & num("B",3) & "</td><td>" & num("I",3) & "</td><td class='freebox'>" & _
freebox & "</td><td>" & num("G",3) & "</td><td>" & num("O",3) & "</td></tr>"
table = table & newrow(4) & newrow(5) & "</table>"
response.write(table)
Loop
It is generating all the tables most of the time, if it doesn't generate a BOF or EOF error. For some reason I can't get it to move to the next employee id etc and it chokes after 11.5 tables as far as inserting the numbers into the db and table.. the problem I feel is that each card inserts 24 row per employee multiply that by 268 employees you have 6,432 rows being inserted to the DB per game which is a lot. Not sure if MSSQL can handle that let alone VBScript and .NET bugs... Ugh such a headache! lol. It chokes if there is say a matching B9 even if it is inserted under a different employee. i.e. it does not duplicate a col/number for the same employee which is good.
Full Page Code Below:
<%@ language="VBSCRIPT" %>
<!-- #include file="connections/db_conn.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 transitional//EN" "http://www.w3.org/td/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>OCIW - Bingo Card Generator</title>
<link rel="stylesheet" href="css/print.css" media="print" type="text/css" />
<link rel="stylesheet" href="css/global.css" media="screen" type="text/css" />
</head>
<body>
<%
numEmployees = iCode("Total")
empName = employeeInfo("EmployeeFirstName")
empName2 = employeeInfo("EmployeeLastName")
sSQL = ""
Dim theCurrentDate, strDateStamp
strDateStamp = FormatDateTime(Now(), vbShortDate)
theCurrentDate = year(date) &_
left("00",2-len(month(date))) & month(date) &_
left("00",2-len(day(date))) & day(date)
Response.Write "<ul id='linklist'>"
Response.Write "<li id='current'><a href='index.asp'>New Game</a></li>"
Response.Write "<li><a href='print_cards.asp'>Print Cards</a></li>"
Response.Write "<li><a href='search_employee.asp'>Search by Employee</a></li>"
Response.Write "<li><a href='master_card.asp'>View Master Game Card</a></li>"
Response.Write "</ul>"
Response.Write "<div class='clearing'> </div>"
Response.Write "<p>" & numEmployees & " bingo cards have been generated and stored to the database on " & strDateStamp & ".</p>"
Response.Write "<p><strong>Game Number: " & theCurrentDate & "</strong></p>"
Response.Write "<p><strong>Start Date: " & strDateStamp & "</strong></p>"
%>
<%
do until c = numEmployees
c = c + 1
Randomize
max=75
min=1
freebox = empName & " " & empName2 & "<br />" & theCurrentDate
table = "<table><thead><th>B</th><th>I</th><th>N</th><th>G</th><th>O</th></thead>"
table = table & newrow(1) & newrow(2)
table = table & "<tr><td>" & num("B",3) & "</td><td>" & num("I",3) & "</td><td class='freebox'>" & _
freebox & "</td><td>" & num("G",3) & "</td><td>" & num("O",3) & "</td></tr>"
table = table & newrow(4) & newrow(5) & "</table>"
response.write(table)
Loop
%>
</body>
</html>
<%
function num(col,row)
If NOT employeeInfo.EOF then
empcode = employeeInfo("EmployeeCode")
Do
num = (Int((max-min+1)*Rnd+min))
cell = col & num & "|"
Loop Until (instr(carddata,cell)=0)
'DO SQL INSERT HERE
sSQL = "INSERT INTO Foo (CompanyCode, EmployeeID, GameNumber, Col, Row) VALUES ('OCIT', '" & empCode & "', '" & theCurrentDate & "', '" & col & "', '" & num & "')"
objConn.Execute(sSQL)
carddata = carddata & cell
employeeInfo.MoveNext
else
Response.Write ""
End If
end function
function newrow(row)
newrow = "<tr><td>" & num("B",row) & "</td><td>" & num("I",row) & "</td><td>" & num("N",row) & "</td><td>" & num("G",row) & "</td><td>" & num("O",row) & "</td></tr>"
end function
%>
This post has been edited by moojoo: 08 November 2006 - 10:36 AM
#43
Posted 08 November 2006 - 02:48 PM
Server.ScriptTimeout = 100
At the start of the page, replacing 100 with the number of seconds you want to allow. It's a shame the db is poorly structured, with some changes you could probably get this thing running many many times faster.
#44
Posted 08 November 2006 - 03:12 PM
#45
Posted 08 November 2006 - 04:03 PM
As for performance, you'd probably want just one record per card as I'd discussed earlier in this post. That'll give you 24 times less inserts.
For the best performance I'd say to write some custom functions in SQL server itself to generate the cards. Then you'd get much better database performance and you wouldn't have all that data going back and forth between ASP and SQL server. Of course to write this you'd need control over the database.
#46
Posted 09 November 2006 - 10:06 AM
[CompanyCode] [EmployeeID] [GameNumber] [b1] [b2].... [i1][i2]... etc so it will be one insert vs 24.
This post has been edited by moojoo: 09 November 2006 - 12:05 PM
#47
Posted 09 November 2006 - 02:08 PM
My recommendation is
[CompanyCode] [EmployeeID] [GameNumber] [CardData]...
By putting all the data in one field you can search it with a single LIKE statement.
#48
Posted 09 November 2006 - 02:39 PM
Ahh its not so bad this way.. one more thing though because now I have it almost working! It is inserting for each employee as it should but it is only inserting 1 number per row.
i.e. employee 002 would get 12, 12, 12, 12.... etc... Trying to figure out how to get num to generate a different number for each field b1, b2, b3, b4 etc.....
So would I place num in a loop or some how have it modify.. but not sure how to do that in VBS... Perhaps set it to an array and call the array in the insert?
Do Until i = numEmployees
i = i + 1
num = (Int((max-min+1)*Rnd+min))
empcode = employeeInfo("EmployeeCode")
sSQL = "INSERT INTO OCIW_EmployeeBingo (CompanyCode, EmployeeID, GameNumber, B1, B2, B3, B4, B5, I1, I2, I3, I4, I5, N1, N2, N3, N4, N5, G1, G2, G3, G4, G5, O1, O2, O3, O4, O5) VALUES ('OCIT', '" & empCode & "', '" & theCurrentDate & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "', '" & num & "')"
objConn.Execute(sSQL)
employeeInfo.MoveNext
Loop
This post has been edited by moojoo: 09 November 2006 - 02:42 PM
#49
Posted 09 November 2006 - 03:29 PM
#50
Posted 13 November 2006 - 11:37 AM
This post has been edited by moojoo: 15 November 2006 - 01:41 PM
#51
Posted 16 November 2006 - 01:53 PM
Do Until i = numEmployees
i = i + 1
empName = employeeInfo("EmployeeFirstName")
empName2 = employeeInfo("EmployeeLastName")
Randomize
Max=75
Min=1
Do
num = (Int((max-min+1)*Rnd+min))
num2 = (Int((max-min+1)*Rnd+min))
num3 = (Int((max-min+1)*Rnd+min))
num4 = (Int((max-min+1)*Rnd+min))
num5 = (Int((max-min+1)*Rnd+min))
num6 = (Int((max-min+1)*Rnd+min))
num7 = (Int((max-min+1)*Rnd+min))
num8 = (Int((max-min+1)*Rnd+min))
num9 = (Int((max-min+1)*Rnd+min))
num10 = (Int((max-min+1)*Rnd+min))
num11 = (Int((max-min+1)*Rnd+min))
num12 = (Int((max-min+1)*Rnd+min))
num13 = (Int((max-min+1)*Rnd+min))
num14 = (Int((max-min+1)*Rnd+min))
num15 = (Int((max-min+1)*Rnd+min))
num16 = (Int((max-min+1)*Rnd+min))
num17 = (Int((max-min+1)*Rnd+min))
num18 = (Int((max-min+1)*Rnd+min))
num19 = (Int((max-min+1)*Rnd+min))
num20 = (Int((max-min+1)*Rnd+min))
num21 = (Int((max-min+1)*Rnd+min))
num22 = (Int((max-min+1)*Rnd+min))
num23 = (Int((max-min+1)*Rnd+min))
num24 = (Int((max-min+1)*Rnd+min))
Loop Until (instr(carddata,cell)=0)
freebox = empName & " " & empName2 & "<br />" & theCurrentDate
empcode = employeeInfo("EmployeeCode")
sSQL = "INSERT INTO Foo_Table (CompanyCode, EmployeeID, GameNumber, B1, B2, B3, B4, B5, I1, I2, I3, I4, I5, N1, N2, N3, N4, N5, G1, G2, G3, G4, G5, O1, O2, O3, O4, O5) VALUES ('OCIT', '" & empCode & "', '" & theCurrentDate & "', '" & num & "', '" & num2 & "', '" & num3 & "', '" & num4 & "', '" & num5 & "', '" & num6 & "', '" & num7 & "', '" & num8 & "', '" & num9 & "', '" & num10 & "', '" & num11 & "', '" & num12 & "', '" & freebox & "', '" & num13 & "', '" & num14 & "', '" & num15 & "', '" & num16 & "', '" & num17 & "', '" & num18 & "', '" & num19 & "', '" & num20 & "', '" & num21 & "', '" & num22 & "', '" & num23 & "', '" & num24 & "')"
objConn.Execute(sSQL)
employeeInfo.MoveNext
Loop
This post has been edited by moojoo: 16 November 2006 - 01:53 PM
#52
Posted 16 November 2006 - 03:31 PM
dim carddata
Max=75
Min=1
Do Until i = numEmployees
carddata = ""
i = i + 1
empName = employeeInfo("EmployeeFirstName")
empName2 = employeeInfo("EmployeeLastName")
Randomize
freebox = empName & " " & empName2 & "<br />" & theCurrentDate
empcode = employeeInfo("EmployeeCode")
sSQL = "INSERT INTO Foo_Table (CompanyCode, EmployeeID, GameNumber, B1, B2, B3, B4, B5, I1, I2, I3, I4, I5, N1, N2, N3, " & _
"N4, N5, G1, G2, G3, G4, G5, O1, O2, O3, O4, O5) VALUES " & _
"('OCIT', '" & empCode & "', '" & theCurrentDate & "', '" & _
num("B") & "', '" & num("B") & "', '" & num("B") & "', '" & num("B") & "', '" & num("B") & "', '" & _
num("I") & "', '" & num("I") & "', '" & num("I") & "', '" & num("I") & "', '" & num("I") & "', '" & _
num("N") & "', '" & num("N") & "', '" & freebox & "', '" & num("N") & "', '" & num("N") & "', '" & _
num("G") & "', '" & num("G") & "', '" & num("G") & "', '" & num("G") & "', '" & num("G") & "', '" & _
num("O") & "', '" & num("O") & "', '" & num("O") & "', '" & num("O") & "', '" & num("O") & "')"
objConn.Execute(sSQL)
employeeInfo.MoveNext
Loop
function num(col)
Do
num = (Int((max-min+1)*Rnd+min))
cell = col & num & "|"
Loop Until (instr(carddata,cell)=0)
carddata = carddata & cell
end function
#53
Posted 16 November 2006 - 03:34 PM
This post has been edited by moojoo: 16 November 2006 - 03:35 PM
#54
Posted 17 November 2006 - 02:22 AM
I set up the carddata variable to clear itself for each card, but during each card it builds up a string of all the numbers used in the card so far, so you can check for duplicates when generating a new number (that's the instr function checking the cardnum string for the new random number, the "loop until" part repeating until the new number isn't found). Because duplicates on the card are ok, just not in the column I had to pass which column the number was going to be used for to the num() function.
Other than that I just used the line continuation character _ to format the SQL string over a few lines so it was easier to read.
For the num() function in detail:
function num(col) '<- column letter is passed Do '<- Begin the number generating loop num = (Int((max-min+1)*Rnd+min)) '<- Set the function name to a new number to be returned cell = col & num & "|" ' <- Combines the letter with the number and a delimiter, like "B23|" Loop Until (instr(carddata,cell)=0) ' <- Check for "B23|" in the carddata string, if it's found loop back to make a new number carddata = carddata & cell ' <- Now you've got a unique number, add "B23|" to the string to be checked on the next num() function call end function ' <- return the new number
The carddata string would look like "B23|B15|B7|I11|I3|I55|..." as it builds, but num() just returns the number part, not the value of cell which has the letter and delimiter in it too.


Help
This topic is locked

MultiQuote









