If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Other > Left join exchange rate table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-11, 03:06
tosa tosa is offline
Registered User
 
Join Date: Feb 2010
Posts: 35
Left join exchange rate table

Hi!

Once again I'm stuck and in need of help from you pros. I'm trying to get the correct exchange rate for each row in a certain table. The db structure looks like this:

tblPayment p
- pmtNum
- currency
- valueDate
- paymentDate

tblPaymentLine pl
- pmtNum
- itemcode
- price

tblExcRate ex
- excRate
- toCurrency
- beginDate
- excRateKey (<- don't know if this is needed)

What I want to select is all rows from tblPaymentLine between certain dates and calculated to a certain currency. The select should go something like "SELECT p.paymentDate, pl.itemcode, CASE p.currency WHEN 'EUR' THEN pl.price ELSE (pl.price*ex.excRate) END AS 'price'". What I can't seem to do though, is left join the currency table. The date for the correct exchange rate would be, as a logical statement: "MAX(ex.beginDate) WHERE ex.beginDate <= p.valueDate and ex.toCurrency=p.currency".

So how do I get this into a complete SQL sentence? It's a Progress OpenEdge database. The query doesn't need to worry about if p.valueDate < ex.beginDate.

Thank you!

Last edited by tosa; 10-21-11 at 03:10.
Reply With Quote
  #2 (permalink)  
Old 10-22-11, 08:05
chedlee88-1 chedlee88-1 is offline
Registered User
 
Join Date: Oct 2011
Posts: 1
Can you break the query into several queries, and store your temp results into a temp table?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On