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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:23:37+00:00 2026-05-11T18:23:37+00:00

Running into a problem. I have a table defined to hold the values of

  • 0

Running into a problem.

I have a table defined to hold the values of the daily treasury yield curve.

It’s a pretty simple table used for historical lookup of values.

There are notibly some gaps in the table on year 4, 6, 8, 9, 11-19 and 21-29.

The formula is pretty simple in that to calculate year 4 it’s 0.5*Year3Value + 0.5*Year5Value.

The problem is how can I write a VIEW that can return the missing years?

I could probably do it in a stored procedure but the end result needs to be a view.

  • 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-11T18:23:37+00:00Added an answer on May 11, 2026 at 6:23 pm

    Taking the assumption by Tom H. that what you really want is a linear interpolation and the fact that not just years, but also months are missing, you need to base every calculation on MONTH, not YEAR.

    For the code below I assume that you have 2 tables (one of which can be computed as part of the view):

    • Yield: contains real data and stored PeriodM in number-of-month rather then name. If you store PeriodName there, you would just need to join on the table:
    • Period (can be computed in the view like shown): stores period name and number of months it represents

    Following code must work (you just need to create a view based on it):

    WITH "Period" (PeriodM, PeriodName) AS (
        -- // I would store it as another table basically, but having it as part of the view would do
                    SELECT  01, '1 mo'
        UNION ALL   SELECT  02, '2 mo' -- // data not stored
        UNION ALL   SELECT  03, '3 mo'
        UNION ALL   SELECT  06, '6 mo'
        UNION ALL   SELECT  12, '1 yr'
        UNION ALL   SELECT  24, '2 yr'
        UNION ALL   SELECT  36, '3 yr'
        UNION ALL   SELECT  48, '4 yr' -- // data not stored
        UNION ALL   SELECT  60, '5 yr'
        UNION ALL   SELECT  72, '6 yr' -- // data not stored
        UNION ALL   SELECT  84, '7 yr'
        UNION ALL   SELECT  96, '8 yr' -- // data not stored
        UNION ALL   SELECT 108, '9 yr' -- // data not stored
        UNION ALL   SELECT 120, '10 yr'
        -- ... // add more
        UNION ALL   SELECT 240, '20 yr'
        -- ... // add more
        UNION ALL   SELECT 360, '30 yr'
    )
    , "Yield" (ID, PeriodM, Date, Value) AS (
        -- // ** This is the TABLE your data is stored in **
        -- // 
        -- // value of ID column is not important, but it must be unique (you may have your PK)
        -- // ... it is used for a Tie-Breaker type of JOIN in the view
        -- //
        -- // This is just a test data:
                    SELECT 101, 01 /* '1 mo'*/, '2009-05-01', 0.06
        UNION ALL   SELECT 102, 03 /* '3 mo'*/, '2009-05-01', 0.16
        UNION ALL   SELECT 103, 06 /* '6 mo'*/, '2009-05-01', 0.31
        UNION ALL   SELECT 104, 12 /* '1 yr'*/, '2009-05-01', 0.49
        UNION ALL   SELECT 105, 24 /* '2 yr'*/, '2009-05-01', 0.92
        UNION ALL   SELECT 346, 36 /* '3 yr'*/, '2009-05-01', 1.39
        UNION ALL   SELECT 237, 60 /* '5 yr'*/, '2009-05-01', 2.03
        UNION ALL   SELECT 238, 84 /* '7 yr'*/, '2009-05-01', 2.72
        UNION ALL   SELECT 239,120 /*'10 yr'*/, '2009-05-01', 3.21
        UNION ALL   SELECT 240,240 /*'20 yr'*/, '2009-05-01', 4.14
        UNION ALL   SELECT 250,360 /*'30 yr'*/, '2009-05-01', 4.09
    )
    , "ReportingDate" ("Date") AS (
        -- // this should be a part of the view (or a separate table)
        SELECT DISTINCT Date FROM "Yield"
    )
    
    -- // This is the Final VIEW that you want given the data structure as above
    SELECT      d.Date, p.PeriodName, --//p.PeriodM,
                CAST(
                    COALESCE(y_curr.Value,
                        (   (p.PeriodM - y_prev.PeriodM) * y_prev.Value
                        +   (y_next.PeriodM - p.PeriodM) * y_next.Value
                        ) / (y_next.PeriodM - y_prev.PeriodM)
                    ) AS DECIMAL(9,4) -- // TODO: cast to your type if not FLOAT
                )  AS Value
    FROM        "Period" p
    CROSS JOIN  "ReportingDate" d
    LEFT JOIN   "Yield" y_curr
            ON  y_curr.Date = d.Date
            AND y_curr.PeriodM = p.PeriodM
    LEFT JOIN   "Yield" y_prev
            ON  y_prev.ID = (SELECT TOP 1 y.ID FROM Yield y WHERE y.Date = d.Date AND y.PeriodM <= p.PeriodM ORDER BY y.PeriodM DESC)
    LEFT JOIN   "Yield" y_next
            ON  y_next.ID = (SELECT TOP 1 y.ID FROM Yield y WHERE y.Date = d.Date AND y.PeriodM >= p.PeriodM ORDER BY y.PeriodM ASC)
    
    --//WHERE       d.Date = '2009-05-01'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try Windows>Preferences>Java>Debug>Step Filtering. Check "Use Step Filters" and simply add… May 12, 2026 at 4:29 pm
  • Editorial Team
    Editorial Team added an answer Rather than a sorted list of primes, given the relatively… May 12, 2026 at 4:29 pm
  • Editorial Team
    Editorial Team added an answer In what language are you going to use it? It… May 12, 2026 at 4:29 pm

Related Questions

(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
The problem is during inserting data from staging table during import routine. The system
Never asked a question here before, I'll try to lay this out as succinctly
Here is the definition of the stored procedure: CREATE OR REPLACE PROCEDURE usp_dropTable(schema VARCHAR,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.