February 24, 2008 at 1:07 pm
I have a column in a table, that is a bit data type with the values of 1 and 0 (1 for True, 0 for False).
How would I modify the column so that I could have 3 predetermined codes instead of 2?
I would like to have the codes (10,15, 100) that represent percentages of totals.
February 24, 2008 at 1:19 pm
percentages, seems you're going to calculate with them, so _must_ be a numerical datatype.
I would store it as decimal (3,2). This way you can avoid the division by 100 .
If you don't like this option, store it as tinyint (smallest integer).
Restrict the values with a constraint.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 24, 2008 at 1:30 pm
Thanks for the quick reply!
I realized however, that I made a mistake in the modification.
I am NOT using percentages, but rather 3 predetermined codes (100 for approved, 50 for pending, and 0 for not approved)
I hope this clarifies it and sorry for the mishap, been working on a project all weekend!!!
February 24, 2008 at 1:55 pm
Hi,
You can have DECIMAL or INT datatypes but this is not the right way to do it. The best thing would be declare this column as CHAR(1) to store the status.
Ex: P -- Pending, A -- Approved, K -- Acknowledge etc....
This will give you more flexibility interms of understanding the data and can accodate future requiments.
Thanks -- Vj
February 24, 2008 at 11:56 pm
In that case, no doubt about it. use the guidance Vijaya Krishna has given.
And as said, restrict it's values with a constraint !
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 25, 2008 at 6:38 am
No... I wouldn't use a CHAR(1) for this... if there are predetermined numeric codes, it's by design... perhaps a requirement for a different app. Having to translate meanings between the server and the app would be confusing, a bit more difficult to verify, and would have the extra overhead of translating everything you put in the table.
I would use the appropriate integer type... for positive whole numbers less than 256, that would be a TINYINT. Same number of bytes as CHAR(1) with lot's more possibilites.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply