matthamilton


We are creating an enterprise application for fuel, and I am fighting with my DBA about the proper way to store volume and currency in the database. We have 2 main arguments. The first argument is whether we should store costs in the database in $ and convert in the presentation layer, or to store the amount and currency in the database. We sell product from the US in dollar but depending on the customer we may invoice in Euro. Our second argument is the same, execept with volume and UOM. We often purchase product by BBL but sell/transfer by gallon, or Ton.

please tell us the best practice for our dilemma.




Re: Store currency and volume in database

Jeroen Alblas


Personally, I would never store a measure in different currencies; particularly if it's in one column. This would mean that for every calculation your application does, for instance a SUM on the amount over a certain period over different customers, it would have to convert every single value before you can do an aggregation. But of course this depends on what the application does. What would be the advantage

I assume the client application does not communicate with SQL Server by ad hoc queries, just by view and/or stored procedures in which you can provide the client application with the data presented in any way which is needed.






Re: Store currency and volume in database

Tom Phillips

I have done similar databases before. You should store the values as the most common currency used, probably US dollars in your case, and convert it to the others as needed. You will also need to store the current exchange rate AT THE TIME OF THE INVOICE, so you can multiply the USD * exchange rate to get your invoiced Euro.

However, I would suggest you never bill in non-US dollars. You are cheating yourself and may be costing your company lots of money because the exchange rate changes hour by hour or at least day by day, depending on the bank.

Take for example, you bill someone on 8/1/2007 73744.4 Euro = $100,000 USD * 0.737444, and they pay you today 73744.4 EURO = $99813.05 USD * 0.738825. In addition you have conversion fees, etc which I will ignore for this example. You just cost your company $186.95 USD. That may not be significant to you. But multiply that times 1000 invoices per month for 12 months, your invoicing software just cost your company $2,243,400 USD. In addition, you need to account for that difference. You sold $100,000 but only got $99,813.05 deposited in the bank.

Moral of the story, always use USD and let the bank and your customer deal with the exchange rate. Yes, I know your customers will complain, but that is the only way to make sure you get what you are owed. You have no control over the exchange rate.