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
 Update this query ?

Author  Topic 

sasan_vm
Yak Posting Veteran

51 Posts

Posted - 2009-02-21 : 10:00:21
Hello, in this query:

SELECT SUM(Amount) AS Recived
FROM dbo.tbl_balance
WHERE (Amount > 0)

if no record see condition (Amount > 0) then Recived set to NULL,
how can change this query in this status Recived set to zero.

Kind Regards,
sasan.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-02-21 : 10:25:48
I am guessing that what you want is this:
SELECT coalesce(SUM(Amount),0) AS Recived
FROM dbo.tbl_balance
WHERE (Amount > 0)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-22 : 01:00:47
[code]SELECT SUM(CASE WHEN Amount > 0 THEN Amount ELSE 0 END) AS Recived
FROM dbo.tbl_balance[/code]
Go to Top of Page

krij
Starting Member

9 Posts

Posted - 2009-02-23 : 04:01:53
SELECT SUM(Isnull(Amount,0)) AS Recived
FROM dbo.tbl_balance
WHERE (Amount > 0)
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-23 : 05:47:34
quote:
Originally posted by krij

SELECT SUM(Isnull(Amount,0)) AS Recived
FROM dbo.tbl_balance
WHERE (Amount > 0)



This won't give you expected result.
Go to Top of Page
   

- Advertisement -