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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:28:40+00:00 2026-06-18T21:28:40+00:00

I want to calculate bill aging days using SQl Server. When a bill is

  • 0

I want to calculate bill aging days using SQl Server. When a bill is cleared, calculate its age.

Date     Invoice#   type   age     Debit   Credit   Balance
01/01              opening  27                      8061
01/01              Cr                      2000     6961
5/01               Cr                      5000     1961
5/1        5       Dr       30     3000             4961
27/1               Cr                      2000     2961
5/2                Cr                      2961        0

The opening balance gets cleared on 27 Jan; so, invoice age is 27 days. And, invoice # 5 is cleared on 5/2; so, its age will be 30 days. How do I do this in SQL Server code?

I have this cledger table in a SQL table.

I could not figure out how to do this recursive task of… selecting bill# and sum all credit till the debit amount is greater than the sum of credit. Using date of that credit transaction, calculate the difference in days between debit bill date and when this bill is cleared.

Any help will be appreciable. Thanks in advance.

  • 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-18T21:28:41+00:00Added an answer on June 18, 2026 at 9:28 pm

    You’re looking for something which is recursive – which considers all previous transactions & aggregates them, comparing them to the current row. You’ll need to join the table to itself, selectively, calculating the balance as of the current date for each row. You could use a recursive CTE, or you could use the T-SQL OVER clause – see http://msdn.microsoft.com/en-us/library/ms189461.aspx .

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

Sidebar

Related Questions

I want to calculate number of days from a date. For example, we have
I want to calculate a new date by adding a number of months to
I want to calculate the percentage of elected people for each member type, I
i want to calculate the NPV ( Net Present Value ) using PHP. Below
I want to calculate downloading time in my ftp download manager. I am using
I want to calculate my countrys((new zealand) local date and time in php but
I want to calculate covariance matrix using Java. Is there any free library to
I want to calculate the age in view class without changing the model class
i want to calculate latest 31-Mar .... suppose date is 1-Jan-2012 i want result
I want to calculate the start date of the last month. I have referred

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.