Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Slow SQL using >date as Criteria

Posted on 2014-01-06
6
Medium Priority
?
737 Views
Last Modified: 2014-01-06
Hi Experts,

I'm linking to a SQL Server table, and importing data. Right now is there only 100.000 records. But in a few Years there will be Millions.

If i just extract all records, then it takes a few sec but if i then say "SELECT * FROM tbl WHERE REG_DATE>[some date]" it gets really slow.

Why is that and is there a way to make it faster?
0
Comment
Question by:DCRAPACCESS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39760331
I'd try adding an index to the date field if not there. This will make the filtering a lot quicker. Select all doesn't need to do anything but bring it all back. While it appears quick, what you see is the first screen - the rest of the data is still loading many seconds later. The moment you sort or filter - a whole lot of work has to happen before you see the first records which is what makes it appear slower.


Kelvin
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39760336
Further to last post, I suspect you are using a normal Access select query. Try doing this as a "pass through" query - you need to write the SQL in SQL Server syntax. This then makes the SQL server do the filter rather than Access and is usually much faster.

Kelvin
0
 

Author Comment

by:DCRAPACCESS
ID: 39760393
Hi Kelvin,

Can you give a sample of a "pass through" query?
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 2000 total points
ID: 39760422
SELECT * FROM tbl WHERE REWG_DATE > '1-jan-2014'

Placed in the body of a pass through query will work.

Then open it as you would an Access query. If the date comes from a parameter or similar - use VBA to contract the SQL and set the pass through query SQL to be whatever you want then open it. They're not much different to Access queries (can only use then for select statements (and not crosstabs)), but must use SQL Server syntax - which is similar but not the same as Access - not that dates are encased in single quotes - as it text.


Kelvin
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 39760462
To create a pass-through query, you need to convert your Access SQL string to T-SQL.  You then create a new query and paste in the SQL string.  The QBE cannot display pass-through queries because a pass-through query is ALWAYS coded in the syntax of the target server.  So, if the query is to run on an Oracle server, you use Oracle syntax.  DB2 server, DB2 syntax, SQL Server, T-SQL, etc.

This is not usually necessary though since Access makes every effort to pass through ALL queries (you can defeat this if you don't understand the process though).  Although there is certainly some overhead associated with the ODBC driver getting involved to convert the "Access" query before sending it off to the server, Access DOES send all queries off to the server for processing and the server returns only the records requested.  So, regardless of whether the query is a pass-through or Jet/ACE, the heavy lifting still gets done on the server.  The pass-through just saves some pre-processing.  The thing you lose with pass-through queries is that they are not updateable and in my mind that is a huge loss.

The only time I have ever actually had to use a pass through query is for bulk updates.  Access wraps each update in a transaction in order to allow you the ability to cancel.  That takes a huge amount of workspace and extra time.  With a pass-through query, you don't get the option to change your mind about applying the updates, once the query is sent, the action happens.

I have found that adding appropriate indexes and occasionally creating views that perform common joins provide sufficient responsiveness.
0
 

Author Closing Comment

by:DCRAPACCESS
ID: 39760467
Works :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question