Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Fill In Missing Dates

Fill In Missing Dates

Fill In Missing Dates

I have a SQL query that is pulling data from my sales table, showing total sales by day.  My problem is that some days our store is not open and there is no data for these dates (thus I get a result set that looks like this):

1/1     4554.44
1/2     4847.54
1/5     5824.54
1/6     4885.43
1/7     5775.35

I still want records to show a zero where there were no sales (like this):

1/1     4554.44
1/2     4847.54
1/3           0
1/4           0
1/5     5824.54
1/6     4885.43
1/7     5775.35

How can I do this?
Replies continue below

Recommended for you

RE: Fill In Missing Dates

What does your existing query look like? Also, what version of PSQL are you using?

Certified Pervasive Developer
Certified Pervasive Technician

RE: Fill In Missing Dates

Version 10, and I'm basically saying:


RE: Fill In Missing Dates

Try something like this....

Create a table with all dates (AllDates) and populate it with all the dates in the range you are interested in.... (You might want to save this for future use... handy as all get out.)

Select AD.TheDate, Sum(S.Sales)
From AllDates as AD Left outer Join AD.TheDate = S.Date
Group by AD.TheDate

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close