views:

333

answers:

2

For my application I need to keep the prefered unit of measurement of a user.
The possible units currently are:

  • Liter (the unit the values in the rest of my database are stored in)
  • Kilogram (varries with the density of the products)
  • US Liquid Gallon (3.785411784 litres)
  • US Liquid Quart (1/4th of above)
  • UK Liquid Gallon (4.54609 litres)
  • UK Liquid Quart (1/4th of above)

I need a way to save these units in an mssql 2005 (and up) database so that there can be no ambiguity and preferably without all the applications keeping an enumeration and without having to create an extra table.
Using an ISO abbreviation would work for the first two, but AFAIK there is none for the last four.
Using the string representation is also asking for trouble..

So besides of finally getting through to the project manager about not using retarded units of measurement, what other suggestions do you have?

+1  A: 
Harper Shelby
Turns out I'll have to in order to make sure all our applications use the same units (codes, conversion rates etc)
borisCallens
+1  A: 

I think you need to reconsider using a table to store these values. The main reason being that you will want to convert from one unit of measure to another and you need to decide on the number of significant digits that is important to your application.

If you have a table, then you can store the litre to X conversion value in the record. This will help keeping all of the other applications in sync in order to reduce rounding and comparison problems.

Chris Lively
but in the case of kilogram it won't have any such value because it needs the density of the material to calculate that...
borisCallens
Storing the conversion values would actually be best done with another table - store 2 ids, and a conversion factor. Storing it in the UOM table would cause you to have poorly normalized data (and force you to add columns when you added UOMs).
Harper Shelby
@Harper: Maybe I'm not understanding you, but I was assuming that everything is stored as litres. The conversion table would simple store what factore was needed to convert from litres to the selected type. This way, if additional types are needed its simply a row that's added, not a column.
Chris Lively
I'm not sure exactly how it's stored - the OP didn't mention it. Having a little experience (which can be dangerous!) with ERP systems for manufacturing, I'm used to seeing a raw quantity with a UOM reference, so that's the pattern I assumed. If the data *is* stored with a known UOM, then you're absolutely correct.
Harper Shelby