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

The Archive Base Latest Questions

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

My question is this, I have a query I’m working on and I have

  • 0

My question is this,

I have a query I’m working on and I have some values that are 0. I want to be able to take a value from a previous month that is not zero and put it in place of the zero. See the example below.

SELECT item,
       stock,
       sold,
       level,
       month,
       year
FROM   agingdata
GROUP  BY item,
          stock,
          sold,
          month,
          year,
          level
HAVING ( item = @Item )
ORDER  BY year,
          month 

enter image description here

So I want take the number 2455 and input it into the stock where it says 0, taking last months balance number as the current months stock level. Is that even possible?

  • 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-13T17:24:56+00:00Added an answer on June 13, 2026 at 5:24 pm

    You can find the previous non-zero level per item (for zero level items) using this query:

    SELECT find.item, find.month, find.year, result.level
    FROM AgingData result 
    JOIN (
      SELECT original.item, original.month, original.year, max(cast(cast(previous.year as varchar) + '-' + cast(previous.month as varchar) + '-1' as datetime)) previous_date
      FROM AgingData original
      JOIN AgingData previous
        ON original.item = previous.item
         AND ((original.year > previous.year)
             OR (original.year = previous.year AND original.month > previous.month))
      WHERE original.level = 0
        AND previous.level != 0
      GROUP BY original.item, original.month, original.year ) find
    ON result.item = find.item
      AND cast(cast(result.year as varchar) + '-' + cast(result.month as varchar) + '-1' as datetime) = find.previous_date
    

    This will work even if the previous non-zero level is several months before.

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

Sidebar

Related Questions

I have this question, just in theory. I do some query results and there
Quick question... I have a query that checks for duplicates that looks like this:
I have this query in MySQL: SELECT pr.*, pr7.value AS `room_price_high` FROM `jos_hp_properties` pr
This is a follow on from another question i made I have this query
Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
I have this question: How could I call a codebehind method from jquery? I
I have a query based on the answer to this question: Handling ties when
I have this query that runs in 7 seconds producing 12,094 records on my
I have this query: SELECT p.text,se.name,s.sub_name,SUM((p.volume / (SELECT SUM(p.volume) FROM phrase p WHERE p.volume
I have this query SELECT Calendar.Production Week FROM Opex WHERE ( Calendar.Production Week BETWEEN

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.