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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
SUM(Switch([Date] = DateAdd('d', - 7, DATE ()), NetAmount) )AS DAY1 
FROM Customer

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

Take a look at this one from msdn:

It shows ways to handle null.

From what you explain - I'd go with IIF

share|improve this answer

Your Answer


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.