Question

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?

Was it helpful?

Solution

I know you don't want to create a new table, but in all honesty, it's the Right Thing™ to do. Add a column with a foreign key reference, and just do it - it'll work better in the end!

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top