Solved

Slow SQL using >date as Criteria

Posted on 2014-01-06
6
703 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 37

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

734 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