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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:50:08+00:00 2026-06-07T08:50:08+00:00

In an SQL Server procedure, I need to get all rows matching some constraints(simple

  • 0

In an SQL Server procedure, I need to get all rows matching some constraints(simple where conditions), and then group them by month.

The goal is to create a graph(in Sql server reporting services), which display all data.

I’ve already something like this:

Select Count(*) AS Count, Month(a.issueDate) AS Month, Year(a.issueDate) AS Year
FROM MyTable a
WHERE
....
GROUP BY YEAR(a.issueDate), MONTH(a.issueDate)

I got my data, I got my graph, but the problem is that if I’ve NOT any rows in “MyTable“, which match my Where conditions, I won’t have any rows.

The result is that I’ve a graph Starting with january, skipping february, and then displaying march.

I cannot post-process data since it’s directly connected to the SQL Server Reporting Services report.

Since I have this problem for ~20 stored procedure, I will appreciate to have the simpliest way of doing it.

Thank you very much for your advices

  • 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-06-07T08:50:09+00:00Added an answer on June 7, 2026 at 8:50 am

    Let’s say you want a specific year:

    DECLARE @year INT;
    SET @year = 2012;
    
    DECLARE @start SMALLDATETIME;
    SET @start = DATEADD(YEAR, @year-1900, 0);
    
    ;WITH y AS (SELECT TOP (12) rn = ROW_NUMBER() OVER (ORDER BY [object_id])-1
      FROM sys.all_objects ORDER BY [object_id])
    SELECT DATEADD(MONTH, y.rn, @start), COUNT(t.issueDate)
      FROM y
      LEFT OUTER JOIN dbo.MyTable AS t
      ON t.issueDate >= DATEADD(MONTH, y.rn, @start)
      AND t.issueDate < DATEADD(MONTH, y.rn + 1, @start)
    GROUP BY DATEADD(MONTH, y.rn, @start);
    

    If it’s not a specific year, then you can do it slightly differently to cover any date range, as long as you provide the 1st day of the 1st month and the 1st day of the last month (or pass 4 integers and construct the dates manually):

    DECLARE @startdate SMALLDATETIME, @enddate SMALLDATETIME;
    SELECT @startdate = '20111201', @enddate = '20120201';
    
    ;WITH y AS (SELECT TOP (DATEDIFF(MONTH, @startdate, @enddate)+1)
        rn = ROW_NUMBER() OVER (ORDER BY [object_id])-1
        FROM sys.all_objects ORDER BY [object_id]
    )
    SELECT DATEADD(MONTH, y.rn, @startdate), COUNT(t.issueDate)
      FROM y
      LEFT OUTER JOIN dbo.MyTable AS t
      ON t.issueDate >= DATEADD(MONTH, y.rn, @startdate)
      AND t.issueDate < DATEADD(MONTH, y.rn + 1, @startdate)
    GROUP BY DATEADD(MONTH, y.rn, @startdate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the value returned from a stored procedure in my Sql
I am in need of a query (or stored procedure rather) for SQL Server
I am in need of a query (or stored procedure rather) for SQL Server
I have an existing stored procedure in SQL Server that I need to call
I need to write a Stored procedure in SQL server whose data returned will
I have sql server procedure, please see below. ALTER PROCEDURE [dbo].[uspInsertDelegate] ( @CourseID int,
I have a SQL server stored procedure which would accept date as input param
I'm looking to take the result of a SQL Server stored procedure and transform
As EF 4.0 released, more support to SQL server Stored procedure. Complex Type can
SQL Server a stored procedure written in C# on the .NET 2.0 framework that

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.