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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:10:56+00:00 2026-06-15T01:10:56+00:00

I am build a report, the output should be like (example): [’11/2012′, 5, 2,

  • 0

I am build a report, the output should be like (example):

['11/2012', 5, 2, 0]
['10/2012', 7, 1, 0]
['09/2012', 2, 3, 0]
['08/2012', 0, 0, 1]
['07/2012', 0, 2, 1]
['06/2012', 2, 1, 0]
['05/2012', 3, 1, 1]
['04/2012', 2, 2, 1]
['03/2012', 5, 0, 0]
['02/2012', 7, 1, 0]
['01/2012', 2, 0, 0]
['12/2011', 3, 0, 1]

For the month part, I need to get the actual month and than list one year back. I have done this with this code:

<%
    DataAtual_PeriodoInicial= Now
    DataFinal_PeriodoInicial= DateAdd("m", -13, Now)
    DO WHILE Datediff("m", DataAtual_PeriodoInicial, DataFinal_PeriodoInicial) <> 0
%>
    ['<% Response.Write(Right("0" & Month(DataAtual_PeriodoInicial), 2)) %>/<% Response.Write(Year(DataAtual_PeriodoInicial)) %>', X, Y, Z]<br>
<%
    DataAtual_PeriodoInicial= DateAdd("m", -1, DataAtual_PeriodoInicial)
    LOOP
%>

So this is generating:

['11/2012', X, Y, Z]
['10/2012', X, Y, Z]
['09/2012', X, Y, Z]
['08/2012', X, Y, Z]
['07/2012', X, Y, Z]
['06/2012', X, Y, Z]
['05/2012', X, Y, Z]
['04/2012', X, Y, Z]
['03/2012', X, Y, Z]
['02/2012', X, Y, Z]
['01/2012', X, Y, Z]
['12/2011', X, Y, Z]

Now I have to throw some numbers instead of X, Y, and Z. I have a table with data like:

11  2012    X
10  2012    X
10  2012    X
10  2012    X
10  2012    Y
10  2012    Y
10  2012    Z
10  2012    Z
10  2012    Z
9   2012    X
9   2012    X
9   2012    X
9   2012    Y
9   2012    Z
9   2012    Z
8   2012    X
8   2012    X
8   2012    Y
8   2012    Y
8   2012    Y
8   2012    Y
8   2012    Y
...

And I start with this select:

SELECT
    datepart(month,SentDate) AS Mes,
    datepart(year,SentDate) AS Ano,
    EventType
FROM
    SomeTable
ORDER BY
    SentDate DESC

I tried some group by, but didn’t sucessed. Do I need some kind of Count? SUM? And how can i finish the come to have the output like the one in the top of this question?

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-06-15T01:10:58+00:00Added an answer on June 15, 2026 at 1:10 am

    Try this

    SELECT
        datepart(month,SentDate) AS Mes,
        datepart(year,SentDate) AS Ano,
        sum(CASE WHEN EventType = 'X' THEN 1 ELSE 0 END ) X,
        sum(CASE WHEN EventType = 'Y' THEN 1 ELSE 0 END ) Y,
        sum(CASE WHEN EventType = 'Z' THEN 1 ELSE 0 END ) Z
    FROM
        SomeTable
    GROUP BY
        datepart(month,SentDate),
        datepart(year,SentDate)
    ORDER BY
        Ano DESC,
        Mes DESC
        SentDate DESC
    

    Demo at http://sqlfiddle.com/#!3/93a11/23/0


    You could also use a PIVOT table

    SELECT * FROM
      (
      SELECT 
        datepart(month,SentDate) AS Mes,
        datepart(year,SentDate) AS Ano,
        EventType
      FROM 
        SomeTable
     ) grouped
    PIVOT (COUNT(eventType) for EventType in ([X],[Y],[Z])) AS pivoted
    ORDER BY
      Ano DESC,
      Mes DESC
    

    Demo at http://sqlfiddle.com/#!3/93a11/16/0

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

Sidebar

Related Questions

I generate EMMA reports during my build, they look like this <report> <stats> <packages
I have a build script where i create a text report file and output
How should I interpret the output given by GCC's -fmem-report flag? What information can
I have a problem with a report that is build using report builder 2.0,
i have to build some financial data report, and for making the calculation, there
I am using a Crystal Report on my website to dynamically build a PDF
I'm trying to get a report built up from data mining our accounting software.
A project I am working on requires me to build a report that is
I have xml that essentialy looks like the following (my actual .xml is a
Below is my query and its output. Is it possible to build my query

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.