Solved

Access/SQL filter question

Posted on 2014-04-01
7
665 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
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!

 
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 500 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

690 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