Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to define a percentage datatype when creating table

Status
Not open for further replies.

CdnGal

Technical User
Oct 13, 2002
1
CA
Hi all...
I am new to sql server so this may seem like a simple question, but I can't find it in any of my resources.

I need to create a table, with a field that is to be used for entering a number such as 25.35%. Basically a percentage with two decimals.

Can you please tell me how I can define this as it is not one of the "standard" datatypes. I know that I could simply use .2535 rather than a percentage as shown above, but I need it to be as the percentage with two decimals.

Thank you!
 
What about using data type int and just prefixing a %?

Tony Did I help?
Vote!
 
create a table with the field as a varchar data type.

insert into your table


select
convert(varchar, .2535 (* 100) + '%') as fld1
from
tbl 1

 
use decimal(5,2) or numeric(5,2)

the 5 indicates that the number will have 5 significant digits -- increase this if you expect percentages of 1000 or greater

the 2 indicates 2 decimal places

thus you can enter values like 25.35

now, if you should want to use these numbers in a calculation, you must realize they are percentages, and remember to divide by 100

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top