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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:26:06+00:00 2026-05-24T21:26:06+00:00

I am currently grouping and summing inventory usage by month: SELECT Inventory.itemid AS ItemID,

  • 0

I am currently grouping and summing inventory usage by month:

SELECT      Inventory.itemid AS ItemID,
            SUM(Inventory.Totalunits) AS Individual_MonthQty,
            MONTH(Inventory.dadded) AS Individual_MonthAsNumber,
            DATENAME(MONTH, Inventory.dadded) AS Individual_MonthAsString
FROM        Inventory
WHERE       Inventory.invtype = 'Shipment'
AND         Inventory.dadded >= @StartRange
AND         Inventory.dadded <= @EndRange
GROUP BY    Inventory.ItemID, 
            MONTH(Inventory.dadded), 
            DATENAME(MONTH, Inventory.dadded)

This gives me the results that I’m expecting:

ItemID  Kit_MonthQty    Kit_MonthAsNumber   Kit_MonthAsString
13188   234             8                   August
13188   45              9                   September
13188   61              10                  October
13188   20              12                  December

Question

What must I do to return zero for months where no data exsits, like this:

ItemID  Kit_MonthQty    Kit_MonthAsNumber   Kit_MonthAsString
13188   0               1                   January
13188   0               2                   February
13188   0               3                   March
13188   0               4                   April
13188   0               5                   May
13188   0               6                   June
13188   0               7                   July
13188   234             8                   August
13188   45              9                   September
13188   61              10                  October
13188   0               11                  November
13188   20              12                  December
  • 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-05-24T21:26:09+00:00Added an answer on May 24, 2026 at 9:26 pm

    In the past, I’ve solved a problem like this by creating a temporary table which will hold all dates needed:

        CREATE TABLE #AllDates (ThisDate datetime null)
        SET @CurrentDate = @StartRange
    
        -- insert all dates into temp table
        WHILE @CurrentDate <=  @EndRange
            BEGIN
                INSERT INTO #AllDates values(@CurrentDate)
                SET @CurrentDate = dateadd(mm, 1, @CurrentDate)
            END
    

    Then, modify your query to join against this table:

    SELECT      ALLItems.ItemId,
                SUM(COALESCE(Inventory.Qty, 0)) AS Individual_MonthQty,
                MONTH(#AllDates.ThisDate) AS Individual_MonthAsNumber,
                DATENAME(MONTH, #AllDates.ThisDate) AS Individual_MonthAsString
    FROM        #AllDates
                JOIN (SELECT DISTINCT dbo.Inventory.ItemId FROM dbo.Inventory)  AS ALLItems ON 1 = 1
                LEFT JOIN Inventory ON DATEADD(dd, - DAY(Inventory.dadded) +1, Inventory.dadded) = #AllDates.ThisDate AND ALLItems.ItemId = dbo.Inventory.ItemId
    WHERE       
                #AllDates.ThisDate >= @StartRange
    AND         #AllDates.ThisDate <= @EndRange
    GROUP BY    ALLItems.ItemId, 
                #AllDates.ThisDate
    

    Then you should have a record for each month, regardless of whether it exists in Inventory.

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

Sidebar

Related Questions

I have an html table with many rows. I'm currently grouping several rows inside
I'm learning regex, and I can't understand the grouping in Java. Currently my regex
Currently, grouping allows only one field in: Views > Basic Settings > Style Options
Below is the code currently I am using for grouping in listview . I
I have a calendar that I generate. Currently it makes the entire month and
I am having problems accessing the right selector. Currently, on mouseover the ENTIRE grouping
I'm currently sorting products based on release date this way: <% @product_months.each do |month,
Currently, solr grouping ( http://wiki.apache.org/solr/FieldCollapsing ) sorts groups by the score of the top
I am currently having an issue with radio buttons and grouping. I have an
Currently I'm working on a extensive form, which I'd like to organise by grouping

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.