Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
SELECT Name,
SUM(Switch([Date] = DateAdd('d', - 7, DATE ()), NetAmount) )AS DAY1 
FROM Customer
GROUP BY Name

My question is how to return the value 0 when the date is not present (an empty field). Should I use SWITCH or IIF or something else?

share|improve this question
    
Use IIf or perhaps Nz() –  Max Vernon Sep 29 '13 at 9:28
    
Do you want to return all dates or a set of dates even though you might not have it? If so, then I would suggest looking at a calendar table to store the list of dates, then you could join to that table and return all dates that you need. –  bluefeet Sep 29 '13 at 12:38

1 Answer 1

Take a look at this one from msdn: http://msdn.microsoft.com/en-us/library/office/aa172237%28v=office.11%29.aspx

It shows ways to handle null.

From what you explain - I'd go with IIF

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.