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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:06:56+00:00 2026-05-24T12:06:56+00:00

I have a table that contains a startdate for each item for example: ID

  • 0

I have a table that contains a startdate for each item

for example:

ID - Startdate
1  - 2011-01-01
2  - 2011-02-01
3  - 2011-04-01
...

I need a query that will give me the count of each item within each month, i need a full 12 month report. I tried simply grouping by the Month(StartDate) but this doesnt give me a zero for the months with no values, in the case above, for march.

so i would like the output to be along the lines of..

Month - Count
  1      20
  2      14
  3      0
...

Any ideas?

Thanks.

  • 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-24T12:06:57+00:00Added an answer on May 24, 2026 at 12:06 pm
    SELECT A.Month, ISNULL(B.countvalue,0) Count
    FROM (SELECT 1 AS MONTH
    UNION 
    SELECT 2 
    UNION 
    SELECT 3 
    UNION 
    SELECT 4 
    UNION 
    SELECT 5 
    UNION 
    SELECT 6 
    UNION 
    SELECT 7 
    UNION 
    SELECT 8 
    UNION 
    SELECT 9 
    UNION 
    SELECT 10 
    UNION 
    SELECT 11 
    UNION 
    SELECT 12 ) A LEFT JOIN (SELECT datepart(month,Startdate) AS Month, Count(ID) as countvalue FROM yourTable GROUP BY datepart(month,Startdate))B
    ON A.month = B.month
    

    Hope this helps

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

Sidebar

Related Questions

I have a table that contains tasks and I want to give these an
I have a table that contains maybe 10k to 100k rows and I need
I have a table that contains form elements that I need to replace if
I have a table that contains the following information date sales 2011-02-13 1 2011-02-13
I have a table that contains my node data in a tree view. Each
I have a table that contains in each row an input and a save
I have a table that contains some blob fields that I don't want to
I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table that contains id, created, user_id. I'm wondering if there is
I have a table that contains members names and a field with multiple ID

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.