dbTalk Databases Forums  

join 2 tables on date to a date range

comp.databases.ms-access comp.databases.ms-access


Discuss join 2 tables on date to a date range in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
colmkav
 
Posts: n/a

Default join 2 tables on date to a date range - 07-10-2012 , 04:23 AM






Is it possible to join to tables on dates but where the join is between a single date in one table joined to a date range of the other?

Basically I have one table with transaction values and currencies for daily dates and a second table that has currency exchange rates for different date ranges

eg

Transaction table fields
Client_id Transaction Value Currency ProcessDate

Currency table fields:
Currency Rate (vs EUR) Startdate Enddate

Basically I want to return the currency rate for the given date from the currency table (depending on which range it falls in)

Reply With Quote
  #2  
Old   
David Hare-Scott
 
Posts: n/a

Default Re: join 2 tables on date to a date range - 07-10-2012 , 06:49 AM






colmkav wrote:
Quote:
Is it possible to join to tables on dates but where the join is
between a single date in one table joined to a date range of the
other?

Basically I have one table with transaction values and currencies for
daily dates and a second table that has currency exchange rates for
different date ranges

eg

Transaction table fields
Client_id Transaction Value Currency ProcessDate

Currency table fields:
Currency Rate (vs EUR) Startdate Enddate

Basically I want to return the currency rate for the given date from
the currency table (depending on which range it falls in)
Try this: start with a cartesian join (ie no join clause at all, yields all
possible combinations) and subset the result in your where clause, eg WHERE
ProcessDate BETWEEN Startdate and Enddate.

D

Reply With Quote
  #3  
Old   
Jan T
 
Posts: n/a

Default Re: join 2 tables on date to a date range - 07-10-2012 , 06:53 AM



SELECT
.....
WHERE (T1.TransactionDate BETWEEN T2.ExchangeRate_StartDate AND
T2.ExchangeRate_EndDate)
.....

should do the trick.

HTH

Jan T


On 10-Jul-12 11:23, colmkav wrote:
Quote:
Is it possible to join to tables on dates but where the join is between a single date in one table joined to a date range of the other?

Basically I have one table with transaction values and currencies for daily dates and a second table that has currency exchange rates for different date ranges

eg

Transaction table fields
Client_id Transaction Value Currency ProcessDate

Currency table fields:
Currency Rate (vs EUR) Startdate Enddate

Basically I want to return the currency rate for the given date from the currency table (depending on which range it falls in)

Reply With Quote
  #4  
Old   
colmkav
 
Posts: n/a

Default Re: join 2 tables on date to a date range - 07-10-2012 , 07:48 AM



Thanks for your answers. I think a join on the condition:

T1.TransactionDate >= T2.ExchangeRate_StartDate AND T1.TransactionDate <= T2.ExchangeRate_EndDate

also works. Was easier than I thought. Thx!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.