sum the decimal value

Posted by Gopal_nivas under Sql Server on 7/18/2011 | Points: 10 | Views : 11288 | Status : [Member] | Replies : 7
hi

i want to sum the decimal values in sql server.
i have two values like this
123.8132924 and 125.8132924

now i want to display the sum of two values. but it display as a whole number 128.

but i want to display the decimal values too.

how to do that.

need ur suggestions with examples.
regards
gopal.s




Responses

Posted by: A4u_6178 on: 7/18/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Gopal,
Looks U might be using Int datatype.Use Datatypes as DECIMAL for the num1,num2 which u want to And result also

Thanks & Regards,

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 7/18/2011 [Member] Starter | Points: 25

Up
0
Down

Like this ..
alter function func_Sum(

@num1 decimal(30,7),
@num2 decimal(30,7))

returns decimal(30,7)
as
begin
declare @num3 Decimal(30,10)
set @num3=@num1+@num2
return @num3
end

To execute..
select dbo.func_Sum(125.8132924,123.8132924)



Thanks & Regards,

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sashys on: 7/18/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

There are some quite a few examples.. Pls see if that helps you...

http://stackoverflow.com/questions/3515488/sql-server-having-trouble-getting-correct-decimal-value-after-cast

Sasikumar .M

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 7/19/2011 [Member] Starter | Points: 25

Up
0
Down
select (123.8132924+125.8132924 ) as Total 


Thanks&Regards
LakshmiNarayana Nalluri.

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 7/19/2011 [Member] Bronze | Points: 25

Up
0
Down
you can use this code sample sum up only the decimal portion of each value.

SUM(F1 - ROUND( F1, 0, 1)

LP MER

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kunalverma31 on: 8/16/2011 [Member] Starter | Points: 25

Up
0
Down
Declare @Tem1 Decimal(18,7)
Declare @Tem2 Decimal(18,7)

set @Tem1=123.8132924
set @Tem2=125.8132924
Select @Tem1+@Tem2
Or
If you have SP and your passing them as parameter then use below code
CAST(@Var1 AS DECIMAL(18,7))+CAST(@Var2 AS DECIMAL(18,7))

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/25/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT SUM(ROSELECT SUM(ROUND(StandardCost,0)) FROM Production.ProductUND(COL1+COL2)) FROM TABLENAME

REGARDS

sriram

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response