Solved

Access/SQL filter question

Posted on 2014-04-01
7
649 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

840 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