Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How can I query sum of rounded number in T-SQL?

Author  Topic 

Indra_G
Starting Member

13 Posts

Posted - 2011-11-01 : 02:58:29
I usually use MS Access database for my VB.NET program. If I have a column with decimal values, and I want to query a sum value of the values AFTER I rounded the numbers say to two decimal places, I usually use this query:
Select Sum(Format(clmValue, "###,##0.##")) from tblTable

it will work just sweet. However, as I am making a program that my Boss asked to use SQL Server, I found out that Format is not an acceptable function in T-SQL. Now, what will be the query in T-SQL dialect that will work the same way? That is to round all the numbers to two decimal places first, then sum it up. Is there a way to do it? I am at loss here, trying to figure out a way...

Thank you so much...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-01 : 03:00:11
[code]
sum( round( clmValue, 2) )
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Indra_G
Starting Member

13 Posts

Posted - 2011-11-01 : 04:56:33
OK, got it! Thank yo so much, Khtan, :)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-01 : 04:59:32
welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -