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
 Sum column values and also check null condition

Author  Topic 

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-03-28 : 10:10:48
Hi,

select '$ '+ CONVERT(varchar,CONVERT(decimal(10,0),CONVERT(money, Amt_Value)),1) as [Amount]
from Products

How can I sum this column values and need to set a validation like the column has null values it has to return zero.

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-03-28 : 18:34:21
[CODE]select '$ '+ CONVERT(varchar,CONVERT(decimal(10,0),CONVERT(money, SUM(Amt_Value)),1) as [Amount]
from Products[/CODE]Aggregate functions, like SUM, will ignore Null values. The exception is COUNT(*) which will count all rows.

===============================================================================
“Everyone wants a better life: very few of us want to be better people.”
-Alain de Botton
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-03-29 : 13:39:02
Also do this data formation at the front end application

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -