I want to store values in certain units along with their corresponding conversions. So for example, there would be following columns
- DateTime
- Millimetres
- Centimetres
- Metres
For a given datetime, the user will provide me a value in any one of the units. So I will need to calculate the rest by myself. Is this better to implement using computed columns or views? I suppose if I am using views or computed columns, I will need to always provide one specific unit as input which I can do in code before inserting. Is their any other way and what is the best way to implement such requirement?
Best Answer
You should store any value using its ISO measure unit. Calculations and conversions should be done at the client side. Don't expect any performance gain over client side conversion when using computed columns.
As far as passing in data in any measure unit, I advise against that design: make the client pass in the data in the ISO measure unit and do any conversion on the client.
If you insist passing data in any unit, this is how an INSTEAD OF trigger could work:
Some data to test:
Results: