Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using ISNULL in SQL Query

Posted on 2005-05-17
2
Medium Priority
?
808 Views
Last Modified: 2008-02-07
In my SUM query if the value is null I want it to return 0.  How do I handle that for example,

SELECT OrderNumber, SUM(OrderTotal) from tblOrders
GROUP BY OrderNumber
0
Comment
Question by:sbornstein2
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 200 total points
ID: 14018581
Try this:
SELECT OrderNumber, ISNULL(SUM(OrderTotal), 0) from tblOrders
GROUP BY OrderNumber
0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 14019547
Alternately, this one works for me:

SELECT
  OrderNumber,
  SUM(coalesce(OrderTotal,0))
from
  deleteme
GROUP BY
  OrderNumber
;

HTH,
DaveSlash
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question