Show 0 if recordset value is null

G

GTN170777

Just a quick question,

I've got a recordset like --

SELECT Count(JBESSiteID) AS TotalJBESent, M.Month, SUM(JBESReceipients) AS
Emails
FROM dbo.JBESent J RIGHT OUTER JOIN Months M ON DATEPART(month, JBESDate) =
M.Month AND JBESSiteID = MMColParam AND DATEPART(year, JBESDate) =
DATEPART(year, GETDATE()) GROUP BY Month
ORDER BY Month

Which works great, but I need it to return a valu of 0 if Emails
SUM(JBESReceipients) is Null,.. any ideas?

Thanks again
 
B

Bob Barrows [MVP]

GTN170777 said:
Just a quick question,

I've got a recordset like --

SELECT Count(JBESSiteID) AS TotalJBESent, M.Month,
SUM(JBESReceipients) AS Emails
FROM dbo.JBESent J RIGHT OUTER JOIN Months M ON DATEPART(month,
JBESDate) = M.Month AND JBESSiteID = MMColParam AND DATEPART(year,
JBESDate) = DATEPART(year, GETDATE()) GROUP BY Month
ORDER BY Month

Which works great, but I need it to return a valu of 0 if Emails
SUM(JBESReceipients) is Null,.. any ideas?
What database? Still SQL 2000? Always tell us please.

Anyways, this is a good situation for the COALESCE function:
, COALESCE(SUM(JBESReceipients),0) AS Emails
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top