Solved

Access/SQL filter question

Posted on 2014-04-01
7
630 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
  • 3
  • 3
7 Comments
 
LVL 57
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 3

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 40

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 57
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 3

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 57

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 3

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now