Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Speed up query
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Speed up query

 Post Reply Post Reply
Author
Shojaee View Drop Down
Newbie
Newbie
Avatar

Joined: 28 March 2003
Location: Iran
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Shojaee Quote  Post ReplyReply Direct Link To This Post Topic: Speed up query
    Posted: 28 March 2003 at 2:53pm

Hello,

I have 2 tables on SQL Server 2000. I need to read some values from one table and search for those values in the second table. I'm using this method:

- Query for all matching records in table 1.

- Put the results in an array (with GetRows).

- Loop through that array and query for records.

The problem is, for only 25 matched records from table 1, it takes about 20 seconds to search the second table. I believe this is too long. What should I do to speed up this operation?

Thanks in advance.

 

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 28 March 2003 at 5:04pm

Try and post your code for us to look at.

Anyway, it would be best to perform the entire query in your initial SQL statement.

To limit the amount of records in one table, depending on your criteria in another, you need to JOIN the tables together. That will save the round trip to the web server and back. http://www.w3schools.com/sql

That said, hats off to ya for using getrows!!  Not many people use/understand its advantages.

Cheers,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
Shojaee View Drop Down
Newbie
Newbie
Avatar

Joined: 28 March 2003
Location: Iran
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Shojaee Quote  Post ReplyReply Direct Link To This Post Posted: 29 March 2003 at 4:59am

This is the first query:

sSQL = "select distinct TAC_ID from TAC_GRP"
rsConfig.CursorType = 3
rsConfig.Open sSQL, objConn
iTotalGroups = rsConfig.RecordCount
rsArray = rsConfig.GetRows
rsConfig.Close

At this point, rsArray contains 25 elements. 

And this is the second query:

For iCount = 0 To (iTotalGroups - 1)
sGroup = rsArray(0, iCount)
sSQL = "select * from TAC_USR where TAC_ATTR='[Global]Groups' and TAC_VAL like '%" & sGroup & "%'"
rsConfig.CursorType = 3
rsConfig.Open sSQL, objConn
Response.Write("<tr>" & vbCRLF)
Response.Write("<td nowrap>" & vbCRLF)
Response.Write("<p align=""left"">"& sGroup & vbCRLF)
Response.Write("</td>" & vbCRLF)
Response.Write("<td nowrap>" & vbCRLF)
Response.Write("<p align=""center"">" & rsConfig.RecordCount & vbCRLF)
Response.Write("</td>" & vbCRLF)
Response.Write("</tr>" & vbCRLF)
Response.Write("<tr><td width=50% height=5></td>")
Response.Write("<td width=50% height=5></td></tr>")
rsConfig.Close
Next

Thanks for your attention.

Back to Top
neehouse View Drop Down
Newbie
Newbie


Joined: 05 April 2003
Location: United States
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote neehouse Quote  Post ReplyReply Direct Link To This Post Posted: 08 April 2003 at 10:24pm

Could try using the power of SQL and Joining to only have one Query.

Also, the like is killing you... Try using exact matches if you can...

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.