Question : Query to pull no service between certain time frame

I have a Access 2007 Database with a names table that holds names of clients and a review table that holds dates a review was done.  How can i create a query to pull the names of people whom have not had a review in a certain period of time.  For instance I want to know who had not had a review from January 1, 2009 to December 31, 2009.

Answer : Query to pull no service between certain time frame

SELECT Name FROM Names_Table N
     LEFT JOIN Review_Table R
          ON N.ID=R.ID
     WHERE R.ID IS NULL
                     OR R.Review_Date < #01/01/2009#
                     OR R.Review_Date > #12/31/2009#

The left join will cause all records from your name table to appear along with information from the review table where it exists.  If a review record doesn't exist then R.ID will be NULL so the first part of your condition is checking if it is NULL which means they don't have any review at all.  

The second part of the condition checks to see if there IS review information if it less than the beginning date of your range (so it doesn't apply) or greater than the ending date of your range (so it also doesn't apply) so if the date is either less than the start of your ranger or greater than the end of your range then it we treat it as if they don't have a review and again it's included in your results.

You'll probably have to build this query as part of a VBA module so you can put in the appropriate date comparisons or link those dates to a form (for the purpose of running a report for example)


Random Solutions  
 
programming4us programming4us