Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 674831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:45:01+00:00 2026-05-14T00:45:01+00:00

I have a simple user production report where daily quotas are tracked. The sql

  • 0

I have a simple user production report where daily quotas are tracked. The sql returns a weeks worth of data for all users and for each day it tracks their totals. The problem is if they are out for a day and have a zero production for that day then the result query just skips that day and leaves it out. I want to return days even if the table has no entries for the person on that day.

table:
user date 
andy 3/22/10
andy 3/22/10
andy 3/23/10
andy 3/24/10
andy 3/26/10


result:
andy
3/22/10    2
3/23/10    1
3/24/10    1
3/25/10    0
3/26/10    1

So my question is how do I get the query to return that 3/25/10 date with a count of 0.

(current query I’m using):

SELECT A.USUS_ID as Processor, CONVERT(VARCHAR(10),A.CLST_STS_DTM,101) as Date,
COUNT(A.CLCL_ID) as DailyTotal

FROM CMC_CLST_STATUS A
WHERE A.CLST_STS_DTM >= (@Day) AND
DATEADD(d, 5, @Day) > A.CLST_STS_DTM

GROUP BY A.USUS_ID, CONVERT(VARCHAR(10),A.CLST_STS_DTM,101)
ORDER BY A.USUS_ID, CONVERT(VARCHAR(10),A.CLST_STS_DTM,101)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:45:01+00:00Added an answer on May 14, 2026 at 12:45 am

    You need to have data for that date otherwise sql cannot produce it.

    The most common way around such a problem is to have a Date Table that contains ALL the dates. Then you can join on this which will allow you to get a zero entry for that date.

    You can either keep this table in your DB permanently, or generate it when you run your query. Which way is best depends on usage, etc.

    EDIT: A CTE method to create your Date Table

    DECLARE @minDate DATETIME;
    DECLARE @maxDate DATETIME;
    
    SET @minDate = '2010-03-01 00:00:00.000';
    SET @maxDate = '2010-03-10 00:00:00.000';
    
    WITH DateRange ([date])
    AS
    (
        SELECT @minDate
        UNION ALL
        SELECT
            DATEADD(DAY, 1, [date])
        FROM
            DateRange
        WHERE
            DATEADD(DAY, 1, [date]) <= @maxDate
    )
    
    SELECT
        *
    FROM
        DateRange
    

    EDIT 2: I haven’t checked this through, but it should work with your database.

    DECLARE @day DATETIME
    
    SET @day = CAST(FLOOR(CAST(GETDATE() AS float)) AS DATETIME);
    
    WITH DateRange ([Date])
    AS
    (
        SELECT @day
        UNION ALL
        SELECT
            DATEADD(DAY, 1, [Date])
        FROM
            DateRange
        WHERE
            DATEADD(DAY, 1, [Date]) <= DATEADD(DAY, 5, @day)
    )
    SELECT
        A.USUS_ID as Processor,
        DateRange.[Date] as Date,
        COUNT(A.CLCL_ID) as DailyTotal 
    FROM
        CMC_CLST_STATUS A
    INNER JOIN
        DateRange
    ON
        A.CLST_STS_DTM >= DateRange.[Date]
    AND
        A.CLST_STS_DTM < DATEADD(DAY, 1, DateRange.[Date])
    GROUP BY
        A.USUS_ID,
        DateRange.[Date]
    ORDER BY
        A.USUS_ID,
        DateRange.[Date]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple web application which lets the user upload local user data
I have this simple code in my user_controller.rb file #listing all users def index
I have a simple User model which is associated to many Town objects using
This is driving me crazy. I have a very simple user control: public int?
FOUND THE ANSWER MYSELF, see below... I'd like to have a very simple user
I have simple question. User supplies URL to my PHP script where I fetch
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end
I have a simple app that will allow a user to tag a location.
I have a simple form where a user can add, edit, and delete people
I have been using the HttpRuntime Cache for caching simple user preferences on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.