June 30, 2008 at 9:29 am
Hi I have an Update SQL which is rounding off and I don't want it too.
Both Fields are decimals and the field that is being updated is a decimal. It's rounding off to 1 instead of leaving it at .96
*********
UPDATE Met_PkgMetrics
SET Pkg_Per = (Installed_Clients/Targetable_Clients)
FROM Met_PkgMetrics
*************
This does not work as well
********
UPDATE Met_PkgMetrics
SET Pkg_Per = cast((Installed_Clients/Targetable_Clients) as decimal(3,2))
FROM Met_PkgMetrics
*************
June 30, 2008 at 9:46 am
Try casting both to decimal(4,3).
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
June 30, 2008 at 10:09 am
I did and get this error
Server: Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.
The statement has been terminated.
******************
UPDATE Met_PkgMetrics
SET Pkg_Per = cast(Installed_Clients as decimal(4,3))/cast(Targetable_Clients as decimal(4,3))
FROM Met_PkgMetrics
June 30, 2008 at 10:21 am
How is this column Pkg_Per defined in the database?
😎
June 30, 2008 at 10:25 am
Also, how are these defined: Installed_Clients Targetable_Clients ?
😎
June 30, 2008 at 10:31 am
All three fields are Decimal
June 30, 2008 at 10:41 am
Doesn't tell me much, decimal what; decimal(10,3), decimal(3,2)...
😎
June 30, 2008 at 10:42 am
Ok this works but is odd
If I change the Pkg_Per to a float data type it works. Although It gives me back way to many decimal places even if I try to force it to 2.
***
UPDATE Met_PkgMetrics
SET Pkg_Per = cast((Installed_Clients/Targetable_Clients) as decimal(3,2))
FROM Met_PkgMetrics
Select * from Met_PkgMetrics
****
As well works as money data type
June 30, 2008 at 10:46 am
Sorry Lynn
You pointed me in the right direction. If I change the data type back to decimal and make it 10,2 it works.
I wasn't aware the scale was actual decimal places.
This works now.
Thanks for the help
June 30, 2008 at 10:49 am
If Pkg_Per is defined like this: Pkg_Per decimal,
Then I know the problem. The problem is the default definition for decimal, if not explicitly defined, is like defining as (18,0) (from BOL).
😎
June 30, 2008 at 1:00 pm
Hi
Please verify the data lenth of the datatype. I am sure this is causing the problem.
Thanks -- Vj
Viewing 11 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply