• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1852
  • Last Modified:

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!
0
freezegravity
Asked:
freezegravity
  • 2
1 Solution
 
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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now