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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:07:37+00:00 2026-06-07T23:07:37+00:00

I’m working with an Inventory Ledger stored as a report/view in our database. When

  • 0

I’m working with an Inventory Ledger stored as a report/view in our database. When exported, it looks like this:

Tran Type         Txn Date     Item     Quantity
Opening Balance   6/30/12      Item1     4
Opening Balance   6/30/12      Item2     7
Shipping          7/14/12      Item2    -1
Opening Balance   6/30/12      Item3     3
Shipping          7/2/12       Item3    -1
Opening Balance   6/30/12      Item4     5
Shipping          7/3/12       Item4    -1
Shipping          7/3/12       Item4    -1
Shipping          7/3/12       Item4    -1
Shipping          7/5/12       Item4    -1
Shipping          7/5/12       Item4    -1
Receiving         7/9/12       Item4    10

Before the export, it doesn’t contain those “Opening Balance” entries, which are generated based on the export period.

We are trying to keep track of how many days each item has been out of stock within a given period. The first stage of this is to create running totals by item, which I had previously been doing through Pivot Tables in Excel. From there, I need to keep a flexible, dynamic count of the number of days each item is at 0 qty for stock (based on month, quarter, or year). Initially, I had hoped to factor this count through pivot tables as well, and I turned to superuser’s help for that. Unfortunately, it seems it may be counter-intuitive to do this type of work through excel, so I’m bringing my issue here.

I have only novice experience in Access and SQL Server. I had some light formal training in Oracle and PL/SQL, but it was a number of years ago. Possibly adding another complication to this, I can’t write or permanently save anything to our system backend (even though I have permissions for it).

So far, I’ve only figured out a T-SQL statement to create running totals by item:

Select 
 TxnDate,
    Quantity,
        Item,
    (SELECT Sum(Quantity)
    FROM DATABASE.dbo.InventoryLedger as D1
    WHERE D1.TxnDate <= D0.TxnDate AND D1.Item = D0.Item) as balance
    FROM DATABASE.dbo.InventoryLedger as D0
    where Item = 'Item4' and TxnDate >= 2012-07-01

I’m lost after this. I don’t know whether I should do some kind of count, or find a way to subtract dates between an Item hitting 0 qty and then being received again later. I’m not sure how to add another aggregated or calculated column based on the already calculated balance column, and I’m not even sure how to translate this query so it will function with my Access file of the same data. I’d accept a solution in either Access or T-SQL format; I’m eager to actually learn T-SQL, while being able to perform the count in Access would let me link the database and make it easier for me to produce direct reports.

I’m also curious if there’d be an easy way to query stock levels for every item on every day? I suppose this would just be calculated using the same exact data, so it would probably just be a waste of time and space, right?

I appreciate any help, folks. I’ve been trying to come up with a solution to measure Out-of-Stock for months now, and this is the closest I’ve been. 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-07T23:07:41+00:00Added an answer on June 7, 2026 at 11:07 pm

    This is much easier with the right set of windows/analytic functions. But I have an idea, which might work.

    First, you can get the cumulative sum by using a self-join.

    Then, also do a self join on this to get the next non-zero cum, and use a group by to get the min date of the next record:

    with tcum as (
         select t.txnDate, t.Item, t.quantity, sum(tprev.quantity) as cumq
         from t left outer join
              t tprev
              on t.item = tprev.item and
                 t.txnDate >= tprev.txnDate
         group by t.txnDate, t.Item, t.quantity
        )
     select tcum.item, tcum.txndate, MIN(tcumnext.txndate) as nextfilldate
     from tcum left outer join
          tcum tcumnext
          on tcum.item = tcumnext.item and
             tcum.date < tcumnext.date and
             tcumnext.cumq > 0 and
             tcum.cumq = 0
    group by tcum.item, tcum.txndate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.