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 database with two tables. Users and Configurations. A user has
I have a simple form on a view page, implemented as a user control,
Cron installation is vixie-cron /etc/cron.daily/rmspam.cron #!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; I Have this simple bash script
I have built a simple Eclipse plugin where a user may use a TableViewer
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement
I develop tools in Autodesk Maya. Many of the tools I build have simple
Should simple JavaBeans that have only simple getters and setters be unit tested?? What

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.