472,345 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

Update a row within a loop with "Order By"

Here is my loop and it runs fine:

----------------------------------------------------
sSQL = "SELECT * FROM STORE_ITEMS"
Set DataRec = DB.execute(sSQL)
if not DataRec.EOF then
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
...
...
updateStock = "update STORE_ITEMS set STR_ITEMS=" &NumInStock& " where
ITEM_ID='" &ITEM_ID& "'"
DB.execute(updateStock)

DataRec.MoveNext
loop 'loop thru items
end if
----------------------------------------------------

But when I added "order by" clause to my query, and it gave me time out
error on this line:
[Microsoft][ODBC SQL Server Driver]Timeout expired
--DB.execute(updateStock)

Here is the code that is not working:
----------------------------------------------------
sSQL = "SELECT * FROM STORE_ITEMS ORDER BY SKU"
Set DataRec = DB.execute(sSQL)
if not DataRec.EOF then
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
...
...
updateStock = "update STORE_ITEMS set STR_ITEMS=" &NumInStock& " where
ITEM_ID='" &ITEM_ID& "'"
DB.execute(updateStock)

DataRec.MoveNext
loop 'loop thru items
end if
----------------------------------------------------

It will be great if anyone can point me to the right direction. Thanks!!!
Dec 15 '06 #1
3 2611
Vanessa wrote:
Here is my loop and it runs fine:

----------------------------------------------------
sSQL = "SELECT * FROM STORE_ITEMS"
Set DataRec = DB.execute(sSQL)
if not DataRec.EOF then
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
...
...
updateStock = "update STORE_ITEMS set STR_ITEMS=" &NumInStock& " where
ITEM_ID='" &ITEM_ID& "'"
DB.execute(updateStock)
Where does NumInStock come from? it seems to me that this could be
accomplished by a single UPDATE statement without the loop. The syntax of
course depends on the database type (and version). Never ask a
database-related question without providing this information.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Dec 15 '06 #2
Vanessa wrote on Thu, 14 Dec 2006 16:25:01 -0800:
Here is my loop and it runs fine:

----------------------------------------------------
sSQL = "SELECT * FROM STORE_ITEMS"
Set DataRec = DB.execute(sSQL)
if not DataRec.EOF then
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
...
...
updateStock = "update STORE_ITEMS set STR_ITEMS=" &NumInStock& " where
ITEM_ID='" &ITEM_ID& "'"
DB.execute(updateStock)

DataRec.MoveNext
loop 'loop thru items
end if
----------------------------------------------------

But when I added "order by" clause to my query, and it gave me time out
error on this line:
[Microsoft][ODBC SQL Server Driver]Timeout expired
--DB.execute(updateStock)
Default timeout for ADO is 30 seconds. Your query is taking more than 30
seconds to run, possibly due to the extra work needed to be done ordering
the data. You will need to use your database's tools to see if you can
optimise the query to run quicker, or a better solution would be as
suggested by Bob to do all the work in the database using a single update
query if possible. In the short term, you could increase the ADO timeout
using the CommandTimeout property on the Connection object, eg.

DB.CommandTimeout = 120 'set timeout to 120 seconds

put this line before you execute the SQL. You may also need to look at
increasing the ASP script timeout to ensure that IIS does not stop the
script before it has chance to finish running, you can use the
Server.ScriptTimeout property to set this.

Dan
Dec 15 '06 #3
Vanessa wrote:
Here is my loop and it runs fine:

----------------------------------------------------
sSQL = "SELECT * FROM STORE_ITEMS"
Set DataRec = DB.execute(sSQL)
if not DataRec.EOF then
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
...
...
updateStock = "update STORE_ITEMS set STR_ITEMS=" &NumInStock& " where
ITEM_ID='" &ITEM_ID& "'"
DB.execute(updateStock)

DataRec.MoveNext
loop 'loop thru items
end if
----------------------------------------------------

But when I added "order by" clause to my query, and it gave me time
out error on this line:
[Microsoft][ODBC SQL Server Driver]Timeout expired
--DB.execute(updateStock)

Here is the code that is not working:
----------------------------------------------------
sSQL = "SELECT * FROM STORE_ITEMS ORDER BY SKU"
Set DataRec = DB.execute(sSQL)
if not DataRec.EOF then
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
...
...
updateStock = "update STORE_ITEMS set STR_ITEMS=" &NumInStock& " where
ITEM_ID='" &ITEM_ID& "'"
DB.execute(updateStock)

DataRec.MoveNext
loop 'loop thru items
end if
----------------------------------------------------

It will be great if anyone can point me to the right direction.
Thanks!!!
Wait a minute ... an ORDER BY on a SELECT statement causes a timeout on
an UPDATE statement??? This makes no sense, unless the SELECT statement
is causing the table to be locked ...

If you really need to retrieve all the records in the table in order to
construct that update statement (and I still believe you don't have to
.... why haven't you replied with the answers to my previous questions?),
then you should probably use either
1. a GetRows array - my preference, but since you used selstar, I cannot
show you how to implement it, so ...
2. a client-side disconnected recordset:

sSQL = "SELECT * FROM STORE_ITEMS ORDER BY SKU"
'http://www.aspfaq.com/show.asp?id=2096

Set DataRec = createobject("adodb.recordset")
DataRec.CursorLocation = 3 '3=adUseClient
DataRec.Open SQL,DB,,,1 '1=adCmdText
Set DataRec.ActiveConnection = nothing
do while not DataRec.EOF
SKU = trim (DataRec("SKU"))
ITEM_ID = trim(DataRec("ITEM_ID"))
....
....
updateStock = "update STORE_ITEMS set STR_ITEMS=" & _
NumInStock & " where ITEM_ID='" & ITEM_ID & "'"
DB.execute(updateStock,,129)
'129=1, adCmdText + 128,adExecuteNoRecords

DataRec.MoveNext
loop 'loop thru items

Again, if you explain where NumInStock comes from, I can show you how to
eliminate this recordset loop entirely.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Dec 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious...
1
by: Simon Wigzell | last post by:
Is it possible to retrieve data with ASP sorted on 2 fields? I've tried : SELECT * FROM ORDER By Field1 AND Field 2 But it gives an error....
14
by: Pedro Werneck | last post by:
Hi I have a class A, with metaclass M_A, and class B, subclass of A, with metaclass M_B, subclass of M_A. A class C, subclass of B must have...
3
by: Ptbrady | last post by:
"Order By" fails in form for linked table. -------------- My A2K database has worked well for several years, but now has been split into...
9
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct...
7
by: Giles | last post by:
An ASP page outputs data from the query "Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER BY threadID, datesent" (Access...
2
by: Richard Hollenbeck | last post by:
I have the following query in a combo box: SELECT courses.courseCode, courses.courseDescription FROM courses ORDER BY courseDescription; I...
16
by: Michael Bell | last post by:
I did an the Open University course MT262. I got 3/4 the way through it and only really came unstuck at classes. Following the advice of many, on...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.