Solved

MS Access 2003 Sub Query

Posted on 2015-01-28
5
207 Views
Last Modified: 2015-01-29
In an access query, I would like to produce a set of results that includes all customers that responded to a particular promotion. That is the easy part. I would like to include in my query results the response date, the last date of any order that preceded the response date and the date of the first order that proceeded the response date.

To do this, I believe that I need some sub queries, but I am not sure how to construct them in respect to linking them the customer number and response date of the underlying query.

Any help would be gratefully appreciated.
0
Comment
Question by:dwcummings
[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
  • 2
  • 2
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40576018
it will also help us if you  upload a db with the table..
0
 
LVL 3

Author Comment

by:dwcummings
ID: 40576069
Thanks for responding.

It is a MS SQL database with a half million customer records and well over a million orders. I think that I got it to work on my own - at least one of the results I was looking for, but it took an inordinate amount of time for the query to run. My code is below:

SELECT R.CustomerId, M.MailingDate, (Select Top 1 DateCompleted from dbo_tblReturns Where CustomerId = R.CustomerId and DateCompleted > M.MailingDate) AS [First]
FROM dbo_tblReturns AS R INNER JOIN dbo_tblMailings AS M ON R.MailingsId = M.MailingsId
WHERE (((M.MailingDate)>#1/1/2014#));

Is there a way to optimize this query? I am sure that when I add the sub query to find the order that precedes the mailing  date, it will slow it down even more.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40576091
try using a pass-through query.
you will need the odbc connection string to the sql server.

you can get that info from the connect field of the msysobjects table

select [connect] from msysobjects where type=4
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 40576383
MailingDate needs an index.  Since Access attempts to "pass-through" every query, switching to a pass-through query will cut some overhead but it won't solve the basic problem which is that the server has to touch all 500,000 rows.  Also MailingsId on dbo_tblReturns must be indexed.
0
 
LVL 3

Author Closing Comment

by:dwcummings
ID: 40578486
Using the pass though query produced dramatic results - seconds vs. 10's of minutes. This is the first time I tried using a pass through query and I am sold and will never go back. That is, once I figured out the syntax differences between Access and TSQL.

Thanks for the help.

Doug
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

734 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