View Single Post
 
Old June 13th, 2007, 05:48 AM
jwhite68 jwhite68 is offline
Registered User
 
Join Date: Jun 2007
Location: Varna, , Bulgaria.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ordering price when multi-currency table

I have a table, lets call it products, that includes 2 columns for price and currency. Its dealing with euros, pounds and dollars.

I want to be able to generate the logic that can sort the table on the price, but by taking into account the currency exchange rates.

So, lets say the PRODUCTS table has the following records:

Price Currency

5 £
1 $
7 €

If you were to simply sort ascending on Price, it would return:

1
5
7

But if we want to return the results ASCending, according to lowest price value first (taking exchange rate into account), it would need to return:

1
7
5

I do have a RATES table stored in SQL, that has this structure:

id from to rate
-------------------
1 eur gbp 0.683
etc

Which has all of the conversion rates for all possibilities stored in it.

Does anyone have any ideas of the type of SQL code that could achieve this?