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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:54:51+00:00 2026-06-06T14:54:51+00:00

my query is returning: +——+——+——+——+——+——+——+——-+——+——+——+——+—–+ | Jan | Feb | Mar | Apr |

  • 0

my query is returning:

+------+------+------+------+------+------+------+-------+------+------+------+------+-----+
| Jan  | Feb  | Mar  | Apr  | May  | Jun  | Jul  |  Aug  | Sep  | Oct  | Nov  | Dec  | Bla |
+------+------+------+------+------+------+------+-------+------+------+------+------+-----+
|    0 |    0 |    0 |    0 |    0 |    0 |    0 |     0 |    0 |    0 |    2 |    0 |  13 |
|    1 |    0 |    0 |    0 |    0 |    0 |    0 |     0 |    0 |    2 |    0 |    0 |  14 |
|    0 |    0 |    0 |    0 |    0 |    9 |    0 |     0 |    0 |    0 |    8 |   37 |  29 |
|    0 |    0 |    0 |    0 |    0 |    0 |    0 |     0 |    0 |    1 |    0 |  374 |  30 |
|    0 |    0 |    1 |    0 |   78 |    2 |    4 |     8 |   57 |  169 |  116 |  602 |  31 |
|  156 |  255 |   79 |   75 |  684 |  325 |  289 |   194 |  407 |  171 |  584 |  443 |  32 |
| 1561 | 2852 | 2056 |  796 | 2004 | 1755 |  879 |  1052 | 1490 | 1683 | 2532 | 2381 |  33 |
| 4167 | 3841 | 4798 | 3399 | 4132 | 5849 | 3157 |  4381 | 4424 | 4487 | 4178 | 5343 |  34 |
| 5472 | 5939 | 5768 | 4150 | 7483 | 6836 | 6346 |  6288 | 6850 | 7155 | 5706 | 5231 |  35 |
| 5749 | 4741 | 5264 | 4045 | 6544 | 7405 | 7524 |  6625 | 6344 | 5508 | 6513 | 3854 |  36 |
| 5464 | 6323 | 7074 | 4861 | 7244 | 6768 | 6632 |  7389 | 8077 | 8745 | 6738 | 5039 |  37 |
| 5731 | 7205 | 7476 | 5734 | 9103 | 9244 | 7339 |  8970 | 9726 | 9089 | 6328 | 5512 |  38 |
| 7262 | 6149 | 8231 | 6654 | 9886 | 9834 | 9306 | 10065 | 9983 | 9984 | 6738 | 5806 |  39 |
| 5886 | 6934 | 7137 | 6978 | 9034 | 9155 | 7389 |  9437 | 9711 | 8665 | 6593 | 5337 |  40 |
+------+------+------+------+------+------+------+-------+------+------+------+------+-----+

as you can see the BLA column starts from 13. i want it to start from 1, then 2, then 3 etc……I do not want any gaps in the data. The reason there are gaps is because all of the months are 0 for that specific bla

how do i get the result set to include ALL values for BLA, even ones that will yield 0 for the months?

here are the desired results:

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Bla |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 1   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 2   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 3   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 4   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 5   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 6   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 7   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 8   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 9   |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 10  |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 11  |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 12  |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 13  |
| 1   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 2   | 0   | 0   | 14  |
| 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 15  |
| …   | …   | …   | …   | …   | …   | …   | …   | …   | …   | …   | …   | …   |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

here’s my query:

SELECT  CASE WHEN SUM(Jan) is not null THEN SUM(Jan) ELSE 0 end Jan,
        CASE WHEN SUM(Feb) is not null THEN SUM(Feb) ELSE 0 end Feb,
        CASE WHEN SUM(Mar) is not null THEN SUM(Mar) ELSE 0 end Mar,
        CASE WHEN SUM(Apr) is not null THEN SUM(Apr) ELSE 0 end Apr,
        CASE WHEN SUM(May) is not null THEN SUM(May) ELSE 0 end May,
        CASE WHEN SUM(Jun) is not null THEN SUM(Jun) ELSE 0 end Jun,
        CASE WHEN SUM(Jul) is not null THEN SUM(Jul) ELSE 0 end Jul,
        CASE WHEN SUM(Aug) is not null THEN SUM(Aug) ELSE 0 end Aug,
        CASE WHEN SUM(Sep) is not null THEN SUM(Sep) ELSE 0 end Sep,
        CASE WHEN SUM(Oct) is not null THEN SUM(Oct) ELSE 0 end Oct,
        CASE WHEN SUM(Nov) is not null THEN SUM(Nov) ELSE 0 end Nov,
        CASE WHEN SUM(Dec) is not null THEN SUM(Dec) ELSE 0 end Dec,
        CASE WHEN Bla > 191 THEN 192 ELSE Bla END Bla
FROM CTE
GROUP BY CASE WHEN Bla > 191 THEN 192 ELSE Bla END
order by bla
  • 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-06T14:54:52+00:00Added an answer on June 6, 2026 at 2:54 pm

    You can use a numbers table or some table that has all values from 1 to 192. You can create that table, make one on the go using a loop or a recursive CTE, using some of the system views, etc. This is one example:

    SELECT  ISNULL(SUM(Jan),0) Jan,
            ISNULL(SUM(Feb),0) Feb,
            ISNULL(SUM(Mar),0) Mar,
            ISNULL(SUM(Apr),0) Apr,
            ISNULL(SUM(May),0) May,
            ISNULL(SUM(Jun),0) Jun,
            ISNULL(SUM(Jul),0) Jul,
            ISNULL(SUM(Aug),0) Aug,
            ISNULL(SUM(Sep),0) Sep,
            ISNULL(SUM(Oct),0) Oct,
            ISNULL(SUM(Nov),0) Nov,
            ISNULL(SUM(Dec),0) Dec,
            A.RN Bla
    FROM (  SELECT *, RN=ROW_NUMBER() OVER(ORDER BY object_id)
            FROM sys.all_objects) A
    LEFT JOIN CTE B
    ON A.RN = CASE WHEN B.Bla > 191 THEN 192 ELSE B.Bla END
    WHERE A.RN BETWEEN 1 AND 192
    GROUP BY A.RN
    order by A.RN
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query returning 24 records for users with code A and 54
I have a query returning the counts of some data, but I do NOT
This is meant to be a query returning ranked results greater than zero. I'm
select station_id,count(case_id) from emer_complaint group by station_id Above query returning the correct result. But,
My sql query is only returning the children of the parent I need it
I have a simple query which is returning records based on the field status
I have a query that is returning in vastly different amounts of time between
I have a simple Nhibernate Linq query that is returning more results than expected:
So I have this awesome MySQL query that's returning me an awesome array >
This query that I have is returning therapists whose 'therapistTable.activated' is equal to false

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.