?
Solved

Access/SQL filter question

Posted on 2014-04-01
7
Medium Priority
?
670 Views
Last Modified: 2014-04-03
Hi Experts,

I got a request to provide an option to filter for an existing report for all employees that did work within the last 3 months or for all employees that didn't work within the last 3 months, however my concern is as follows, since the data (to filter) is to be taken from a scheduling table that contains a large quantity of records (over half million), if I would just add to the forms/Report filter "where EmployeeID in/not in (Select employeeid from scheduletbl where day > date()-90)" it will freeze...
0
Comment
Question by:bfuchs
[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
  • 3
7 Comments
 
LVL 58
ID: 39970595
Bad idea....in general, stay away from sub-queries if at all possible.   What your doing then for *every* row is running a query.

You'd be far better off to do a query on the schedule table, with the Date()-90 check and a SELECT DISTINCT returning only the EmpID, then join this to the report query using an outer join, and a check for Not Null on the EmpID field from that "table".

Jim.
0
 
LVL 4

Author Comment

by:bfuchs
ID: 39970646
Hi Jim,
Yeah, what you're describing is exactly what I do when I know this is what the user always want...however in this case, this is just an option they want to add to the existing filter options...and for the most part it will not be looking for scheduling data at all,  Therefore I am wondering what is the ideal way of dealing with such...Are you saying that I must change the record source according to what the user decides to filter?
0
 
LVL 41

Expert Comment

by:Sharath
ID: 39971469
Tri with EXISTS clause instead of IN. Do you have index on EmployeeID and Day columns?
where exists (Select 1 from scheduletbl as t2 where t1.EmployeeID = t2.EmployeeID and day > date()-90)

Open in new window

0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 58
ID: 39971867
From your question, it sounds like the same query to me in either case.

In one, you check for EmpID being null (meaning not worked in the last 90 days), and in the other not null (meaning they worked in the last 90 days.

If your don't care if they worked or not, then EmpID can be null or not null.

Jim.
0
 
LVL 4

Author Comment

by:bfuchs
ID: 39973158
@ Sharath,
I can give it a try, however highly doubt it would run in an acceptable phase, as it will still have to run it for every single row, the way Jim described above..

@ JDettman ,
This is a form that is based on a join of 3 tables,  and in total have about 15K records, now one of them has a field EmployeeID that we are talking about..
here is the issue, if I will join these with the huge Schedule table, the performance will suffer badly, let alone the fact that we need to do a distinct on that schedule table...

One more thing to add, those 3 tables are access based, only the huge schedule table is  in SQL, therefore I cant even count on the sql server to perform this task..
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 39974696
<<here is the issue, if I will join these with the huge Schedule table, the performance will suffer badly, let alone the fact that we need to do a distinct on that schedule table...>>

 I think you'll be surprised, especially if the EmpID and date is indexed in SQL.

 But you'll be really surprised if you build a view in SQL as I outlined.   You will not get a huge table back, but one row per employee, which is what your joining to.

Jim.
0
 
LVL 4

Author Closing Comment

by:bfuchs
ID: 39976737
Thanks Jim,
Initially it did froze, waited till the end of the day, then created an index on the employeeid field, and that took care of the problem.
(Just hope that will perform as well tom when there are multiple users logged into the server)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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