Reputation: 3195
I'm not really sure how to articulate this question. So please point me in the right direction if this has already been answered.
Basically I want to store the unit types so that I can do some comparison later based on user selection. For example, user can select "day", "week", "month", "year" as a unit type. Then they need to select a number associated to that unit type. Having this number and the unit type will allow my program to do some calculation based on user selection.
Another example is for selecting other unit types like metrics and imperial that is, mm, cm, m, km, or inch, feet, mile, etc etc...
Do I just store them as varchar and then just do a string comparison in my program?
Upvotes: 1
Views: 2929
Reputation: 23876
I think what you need is to store the measurement value in a consistent format (for example mm) then when a user picks a unit type you would have a table of the conversion from the unit type to the type you stored (ie inches to mm) this was the sql query can perform the math needed.
Or if you want to get a little more complicated you could use 2 columns to store the data - the unit type and the value - then you could use the conversion table to convert between.
Upvotes: 0
Reputation: 1002
Varchar is always the option of last resort. Try and create a numbering system for it like with ids. So, you could have another table for relationships that would have the text value like "day","month", etc matching the numbering system.
Upvotes: 1