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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:17:33+00:00 2026-06-08T14:17:33+00:00

I’ve been working for around two weeks now on building some detailed reporting options

  • 0

I’ve been working for around two weeks now on building some detailed reporting options for the company I work at. I asked a question here sometime last week or the week before, and that got me started on a query, which I eventually tightened up substantially.

I’m starting from an inventory ledger which just keeps track of single transactions. The goal is to build a more thorough ledger that will keep a running stock total, a running sales total, and if an item went out of stock, it will track the days until resupply.

The initial query used a With … as statement to define the table with its aggregates before doing the self join on the aggregated columns. Unfortunately, I can’t do the same thing to create a view, so I need to find a way to create those aggregates differently that will still allow me to self-join on them to keep my totals in order.

Here is how I’ve retooled my statement so far:

Create View 'QLedger' as
Select tcum.txnid,
        tcum.Item, 
        tcum.TxnDate, 
        tcum.[Tran Type], 
        tcum.Quantity,
        tcum.cumq 

 from (select *, SUM( Quantity ) 
            OVER (PARTITION BY InventoryLedger.Item 
            ORDER BY InventoryLedger.TxnID
            ROWS UNBOUNDED PRECEDING ) cumq, 
            abs( 
                sum( 
                    case when [Tran Type] = 'Shipping' 
                    or [Tran Type] = 'Customer Return' 
                    then Quantity end) 
                    over (partition by qryrptInventoryLedger.item 
                            order by InventoryLedger.txnid 
                                    rows unbounded preceding)) LifeSales
            from InventoryLedger) tcum 
 left outer join InventoryLedger tcumnext
 on tcum.Item = tcumnext.Item
 and tcum.TxnID < tcumnext.TxnID 
 and
 tcum.cumq = 0 and tcumnext.cumq >0
 where tcum.Item = '103-02'
 and tcum.cumq = 0
 group by tcum.TxnID, tcum.TxnDate, tcum.Item, tcum.[tran type], tcum.Quantity

This is almost right, except the table I’m self joining to (tcumnext) doesn’t have a running/cumulative quantity column to compare to tcum. I can’t at all figure out how to make one to compare with. Can anyone help me out? I’d really appreciate it. It’s exciting and frustrating to be so, so close after working on this for so long.

  • 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-08T14:17:37+00:00Added an answer on June 8, 2026 at 2:17 pm

    You can use a with statement in a view:

    create view xxx as
        with <blah blah blah>
        select <your query>
    

    Does this solve your problem?

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6

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.