Solved

Access/SQL filter question

Posted on 2014-04-01
7
646 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 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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

773 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