Saving percent with two decimal places in SQL Server

Hello:

So, here's a relatively easy one I think:

In a table designed like: tblProject (ProjectName, PercentOverBudget)

I want the PercentOverBudget field to be a percentage with two decimal places max and 4 places to the left of the decimal (so a valid field could be 1115.53).

I have two questions:

1. How should I declare the PercentOverBudget in SQL Server 2005?
2. I am going to write a stored procedure from an asp.net web application that is going to fill this table. How will I refer to the type of data in ASP.Net?

Thanks!
freezegravityAsked:
Who is Participating?
 
YveauCommented:
Try this:

create table #Y (col1 decimal(6,2))

insert into #Y values(100)
insert into #Y values(10.1234)
insert into #Y values(0)
insert into #Y values(12345.6789)

select * from #Y

-->> Output:

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)
Msg 8115, Level 16, State 8, Line 6
Arithmetic overflow error converting numeric to data type numeric.
The statement has been terminated.
-- >> 12345 is to big ! Error is expected !

-->> Result:

col1
---------------------------------------
100.00
10.12
0.00


So the data type you are looking for is decimal(6,2)

Hope this helps ...
0
 
YveauCommented:
Glad I could help and thanks for the grade !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.