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 166201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:03:23+00:00 2026-05-11T12:03:23+00:00

I feel like I’ve seen this question asked before, but neither the SO search

  • 0

I feel like I’ve seen this question asked before, but neither the SO search nor google is helping me… maybe I just don’t know how to phrase the question. I need to count the number of events (in this case, logins) per day over a given time span so that I can make a graph of website usage. The query I have so far is this:

select     count(userid) as numlogins,     count(distinct userid) as numusers,     convert(varchar, entryts, 101) as date  from     usagelog  group by     convert(varchar, entryts, 101) 

This does most of what I need (I get a row per date as the output containing the total number of logins and the number of unique users on that date). The problem is that if no one logs in on a given date, there will not be a row in the dataset for that date. I want it to add in rows indicating zero logins for those dates. There are two approaches I can think of for solving this, and neither strikes me as very elegant.

  1. Add a column to the result set that lists the number of days between the start of the period and the date of the current row. When I’m building my chart output, I’ll keep track of this value and if the next row is not equal to the current row plus one, insert zeros into the chart for each of the missing days.
  2. Create a ‘date’ table that has all the dates in the period of interest and outer join against it. Sadly, the system I’m working on already has a table for this purpose that contains a row for every date far into the future… I don’t like that, and I’d prefer to avoid using it, especially since that table is intended for another module of the system and would thus introduce a dependency on what I’m developing currently.

Any better solutions or hints at better search terms for google? Thanks.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T12:03:23+00:00Added an answer on May 11, 2026 at 12:03 pm

    Frankly, I’d do this programmatically when building the final output. You’re essentially trying to read something from the database which is not there (data for days that have no data). SQL isn’t really meant for that sort of thing.

    If you really want to do that, though, a ‘date’ table seems your best option. To make it a bit nicer, you could generate it on the fly, using i.e. your DB’s date functions and a derived table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this question has been asked before but the answers seem pretty
I feel like the answer to this question is really simple, but I really
I feel like this question ought to have been covered, but I can't seem
I feel like this question has probably been asked a thousand times already, so
I feel like this is a rather simple question, but I can't seem to
I feel like this is a very noob question.. but I just can't get
I feel like this question has already been asked and answered, yet I couldn't
I feel like this must have been asked, but I'm unable to find it
I feel like this is probably a pretty simple question, but this is my
I feel like this should be an easy question but I can't seem to

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.