What should be the best way to store a percent value in SQL-Server?

sql, sql-server, t-sql, types

Solution

decimal(p, s) and numeric(p, s)

p (precision):

The maximum total number of decimal digits that will be stored (both to the left and to the right of the decimal point)

s (scale):

The number of decimal digits that will be stored to the right of the decimal point (-> s defines the number of decimal places)

0 <= s <= p.

- p ... total number of digits

- s ... number of digits to the right of the decimal point

- p-s ... number of digits to the left of the decimal point

Example:

CREATE TABLE dbo.MyTable
( MyDecimalColumn decimal(5,2)
 ,MyNumericColumn numeric(10,5)
);

INSERT INTO dbo.MyTable VALUES (123, 12345.12);

SELECT MyDecimalColumn, MyNumericColumn FROM dbo.MyTable;

Result:

MyDecimalColumn: 123.00 (p=5, s=2)

MyNumericColumn: 12345.12000 (p=10, s=5)

link: msdn.microsoft.com

Problem

I want to store a value that represents a percent in SQL server, what data type should be the prefered one?

Original source