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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:20+00:00 2026-06-15T10:45:20+00:00

Below is my new sql so far as i do not manage to use

  • 0

Below is my new sql so far as i do not manage to use Dale M advice,

SELECT
all_months.a_month_id AS month,
year($P{date}) as year,
count(case when clixsteraccount.rem_joindate between DATE_FORMAT($P{date}-INTERVAL 2   MONTH, '%Y-%m-01') AND $P{date} THEN clixsteraccount.rem_registerbycn end) AS
total_activation,
'ACTIVATION(No)' AS fake_column

FROM clixsteraccount right join all_months on all_months.a_month_id = date_format(clixsteraccount.rem_joindate,'%m') and
(clixsteraccount.rem_registrationtype = 'Normal')and(clixsteraccount.rem_kapowstatus='pending' or clixsteraccount.rem_kapowstatus='success')

GROUP BY year,month

HAVING month BETWEEN month(date_sub($P{date},interval 2 month)) and month($P{date})

So, what i do is create a table with two fields, a_month_id(1,2,3…,12) and a_month(name of months). Sql above does give me what i want which is to display previous 3 months even the months before is not exist.
exp: data start on July. So, i want to display May,June and July data like 0,0,100.

The problem occur when it comes to next months or next year. When i try to generate sql based on parameter on Jan, it doesn’t work like i thought. I do realize the problem are with ‘Having’ condition. Do anyone have idea how to improvised this sql to make it continue generate in the next,next year.

Thank you in advanced.

  • 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-15T10:45:21+00:00Added an answer on June 15, 2026 at 10:45 am

    OK, I will make a few suggestions and give you an answer that will work on SQL Server – you will need to make any translations yourself.

    I note that your query will aggregate all years together, i.e. Dec 2012 + Dec 2013 + Dec 2014 etc. Based on your question I don’t think that is your intention so I will keep each distinct. You can change the query if that was your intention. I have also not included your selection criteria (other than by the month).

    I suggest that you utilize an index table. This is a table stored in your database (or the master database if possible) with an clustered indexed integer column running from 0 to n where n is a sufficiently large number – 10,000 will be more than enough for this application (there are 12 months in a year so 10,000 represents 833 years). This table is so useful everyone should have one.

    SELECT  DATEADD(month, it.id, 0 ) AS month
        ,ISNULL(COUNT(clixsteraccount.rem_registerbycn), 0) AS registration
        ,'REGISTRATION(No)' AS fake_column
    FROM    cn
        INNER JOIN ON ca.rem_registerbycn = cn.cn_id
        clixsteraccount ca 
        RIGHT JOIN
        IndexTable it ON it.id = DATEDIFF(month, 0, clixsteraccount.rem_joindate)
    WHERE   it.id BETWEEN DATEDIFF(month, 0, @StartDate) - 3 AND DATEDIFF(month, 0, GETDATE())
    GROUP BY it.id
    

    The way it works is by converting the clixsteraccount.rem_joindate to an integer that represents the number of months since date 0 (01-01-1900 in SQL Server). This is then matched to the id column of the IndexTable and limited by the dates you select. Because every number exists in the index table and we are using an outer join it doesn’t matter if there are months missing from your data.

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

Sidebar

Related Questions

Please explain the SQL query given below. I m new with SQL and struggling
I am using .NET 3.5 and need to convert the below select new result
I add a select control to a ASPX page like below: hgc = new
im using vs2010 and have a sql statment shown below select deptId, deptName, Detail
Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =
I m new with jquery.Below is my html table which is in content page.In
HI: Below code is from RequestFactoryEditorDriver: /** * Returns a new array containing the
I am new to web services and below I am sharing my understanding so
Using the code below I can insert a new row to my table (
i have an array below string stringArray = new stringArray[12]; stringArray[0] = 0,1; stringArray[1]

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.