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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:04:03+00:00 2026-06-08T15:04:03+00:00

Basically I have an invoice lines for a below account as below: BillID AccountID

  • 0

Basically I have an invoice lines for a below account as below:

BillID     AccountID     BilledFrom        BillTo      Days     Price
 38         3456         10/10/2012       10/11/2012    30       86p
 39         3456         11/11/2012       11/12/2012    30       87p
 40         3456         12/12/2012       30/12/2012    18       81p

The user would like to refund the customer for a partial date Range, therefore the user will need to enter a date from and date to date:

Date From: 18/10/2012     DateTo: 14/12/2012

This will cause credit lines to refund the client working out the days and price for each line. I need to return each line and show the cut off points. As you can see the ranges entered span across the 3 invoice lines.

The result needed is:

BillID  AccountID  BilledFrom    BillTo     RangeStart  RangeEnd    Days  Price
 38       3456     10/10/2012   10/11/2012  18/10/2012  10/11/2012   22    86p
 39       3456     11/11/2012   11/12/2012  11/11/2012  11/12/2012   30    87p
 40       3456     12/12/2012   30/12/2012  11/11/2012  11/12/2012    2    81p

The results basically will bring back the initial applicable invoice line but work out how this range fits and calculates the days against the bill from and bill to from the date range entered.

I need a function either in SQL to provide this result. Any Help would be appreciated. Thank you 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-08T15:04:06+00:00Added an answer on June 8, 2026 at 3:04 pm

    try this:

      declare @DateFrom date='10/18/2012'     
     declare @DateTo date='12/14/2012'
    
     select T.BillID,T.AccountID,T.BilledFrom,T.BillTo,
         case when BilledFrom<@DateFrom then @DateFrom else BilledFrom end [RangeStart], 
         case when BillTo<@DateTo then BillTo else @DateTo end [RangeEnd],DATEDIFF(D,case when BilledFrom<@DateFrom then @DateFrom else BilledFrom end ,case when BillTo<@DateTo then BillTo else @DateTo end ) [Days],Price
         from t_account  T
    

    SQL Fiddle Demo

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

Sidebar

Related Questions

I basically have a QMainWindow, and a Dialog window whose constructor is shown below;
I have a problem. I have 4 tables: Invoice_Payment, Invoice, Client, and Calendar Basically,
I have an invoicing system that manages debits and credits. Basically the invoice amount
I have an invoice. Line items are arranged in a table, basically like this:
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a unix process running and it is doing some heavy processing
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I basically have 7 select statements that I need to have the results output

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.