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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:55:46+00:00 2026-06-17T17:55:46+00:00

Can anyone assist in a sql statement I am trying to write? I’m using

  • 0

Can anyone assist in a sql statement I am trying to write? I’m using SSRS r1 (either sql or ssrs solution is fine)

How do I:

  • show count measure split by month and year
  • for each of those months, I want to count the previous cumulative 12 months

e.g.

2012 jan: counts feb 2011 - jan 2012
2012 feb: counts mar 2011 - feb 2012
2012 mar: counts apr 2011 - mar 2012

I have started this code but it’s incorrect, however it gives you an idea of what I am trying to achieve (this issue is I have to calc month and year from a date)

select 
    count(a.measure) count
    ,month(a.StartDate)
    ,year(a.StartDate)
from
    a
where 
    a.StartDate >=  DATEADD(mm,DATEDIFF(mm,0,@datepromt)-12,0) as startdateYrAgo --1st month 1 year ago 01/01/2012 
    and a.StartDate <= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@datepromt)+1,0)) as startdateEOM --last day of month 31/01/2013
group by 
    month(a.StartDate)
    ,year(a.StartDate)
  • 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-17T17:55:47+00:00Added an answer on June 17, 2026 at 5:55 pm

    Here you have an idea for the query, it have to look something like below;

    SELECT 
     periods.year
    ,periods.month
    ,measures.cnt
    FROM (
        SELECT DISTINCT
          year = YEAR(StartDate)
        , month = MONTH(StartDate)
        , month_running = DATEDIFF(mm, 0, StartDate) 
        FROM a
        GROUP BY YEAR(StartDate), MONTH(StartDate), DATEDIFF(mm, 0, StartDate) 
    ) periods
    JOIN (
        SELECT month_running = DATEDIFF(mm, 0, StartDate), cnt = COUNT(measure) 
        FROM a
        GROUP BY DATEDIFF(mm, 0, StartDate) 
    ) measures
    ON measures.month_running BETWEEN periods.month_running - 12 AND periods.month_running - 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone assist me in connecting via Management Studio using the hostname provided by
can anyone assist me in finding the proper formula for quad normalization ? using
Please can anyone assist with hiding the available databases on sql server 2008R2 or
Can anyone assist me with the following. I've configured spring authentication fine so -
Can anyone assist in the following. I have a field notes inside a mysql
Can anyone assist me in getting a Python script running on Hostgator Shared hosting?
Can anyone assist me in getting a function to be called, in this example
Can anyone let me know how can we change the value of kendo combobox
Can anyone enlighten me to a way I can Highlight the content of an
Can anyone explain to me why this program: for(float i = -1; i <

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.