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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:29:57+00:00 2026-05-23T15:29:57+00:00

I have a table with rate at certain date : Rates Id | Date

  • 0

I have a table with rate at certain date :

          Rates

Id  |     Date      |  Rate
----+---------------+-------
 1  |   01/01/2011  |  4.5
 2  |   01/04/2011  |  3.2
 3  |   04/06/2011  |  2.4
 4  |   30/06/2011  |  5

I want to get the output rate base on a simple linear interpolation.

So if I enter 17/06/2011:

Date        Rate
----------  -----
01/01/2011  4.5
01/04/2011  3.2
04/06/2011  2.4
17/06/2011  
30/06/2011  5.0

the linear interpolation is (5 + 2,4) / 2 = 3,7

Is there a way to do a simple query (SQL Server 2005), or this kind of stuff need to be done in a programmatic way (C#…) ?

  • 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-05-23T15:29:57+00:00Added an answer on May 23, 2026 at 3:29 pm

    Something like this (corrected):

    SELECT CASE WHEN next.Date IS NULL  THEN prev.Rate
                WHEN prev.Date IS NULL  THEN next.Rate
                WHEN next.Date = prev.Date  THEN prev.Rate
                  ELSE ( DATEDIFF(d, prev.Date, @InputDate) * next.Rate 
                       + DATEDIFF(d, @InputDate, next.Date) * prev.Rate
                       ) / DATEDIFF(d, prev.Date, next.Date)
           END AS interpolationRate 
    FROM
      ( SELECT TOP 1 
            Date, Rate 
        FROM Rates
        WHERE Date <= @InputDate
        ORDER BY Date DESC
      ) AS prev
      CROSS JOIN
      ( SELECT TOP 1 
            Date, Rate 
        FROM Rates
        WHERE Date >= @InputDate
        ORDER BY Date ASC
      ) AS next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an exchange rate table. I need to get current rate and previous
I have a table that looks like this: Month | Year | Rate 2011
i have table structure with 3 colums (column1, column2, column3) and i want to
I have table with 3 columns A B C. I want to select *
I have a table, Sheet1$ that contains 616 records. I have another table, Rates$
i have interest rate and amount in a table where interest rate are ranged
I have a table in PostgreSQL DB like this: Client | Rate | StartDate|EndDate
I have a table in PostgreSQL DB like this: Client | Rate | StartDate|EndDate
I have this table where you add taxes. |Name | Rate | Description |
I have a table as below Rate Effective_Date ---- -------------- 5.6 02/02/2009 5.8 05/01/2009

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.