Solved

Slow SQL using >date as Criteria

Posted on 2014-01-06
6
693 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 500 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 36

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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