View Single Post
  #10  
Old May 14th, 2010, 04:01 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Lag 1 day relationship

If you stick around and read more of the posts, I think you'll realize
that John was not trying to be nasty or sarcastic. "Gently chiding" at
the worst, but the intent was to make you smile and prompt you for
further information. Intentions are very difficult to convey in
plain-text messages like this so please try not to jump to conclusions
so quickly. :-)

And his post did serve the purpose of getting you to further clarify
things which allowed me to realize that T2 was your holiday table, and
allowed you to get your solution.

Michelle wrote:
Bob,

This is exactly what I was looking for. Yes, T2 is essentially my
holiday table. I wasn't thinking of it that way before. Thank you
kindly for your help.


John, I really didn't appreciate your prior sarcastic comments. It
wasn't at all necessary.


Oops, I forgot the ID relationship in that saved query (although it
might not make any difference ...)

Select T1.ID,T1.date,
(select max(T2.date) from T2 WHERE T1.ID=T2.ID
AND T2.date T1.date)
As T2date
FROM T1


Bob Barrows wrote:
It seems that T2 is essentially your holiday table. It's not going
to perform well, but a correlated subquery will do the trick.
Create this saved query (call it Q1):

Select T1.ID,T1.date,
(select max(T2.date) from T2 WHERE T2.date T1.date)
As T2date
FROM T1


Now you can join Q1 to T2:

SELECT Q1.ID, Q2.date,T2.whatever
FROM Q1 JOIN T2 ON Q1.ID=T2.ID AND Q1.T2date=T2.date


--
HTH,
Bob Barrows