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

  • Home
  • SEARCH
  • 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 7074423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:03:22+00:00 2026-05-28T06:03:22+00:00

For a given point in time, an asset has an effective price. Some assets

  • 0

For a given point in time, an asset has an effective price. Some assets have a new price once a week, some once a day. The most recent price is the “effective price”.

The temporal table that stores the described relationship looks like this:

CREATE TABLE dbo.AssetPrice
(
    AssetId int NOT NULL -- FK to the table dbo.Asset
    ,EffectiveDate datetime NOT NULL
    ,Price decimal NOT NULL
    CONSTRAINT PK_AssetPrice PRIMARY KEY CLUSTERED (AssetId,EffectiveDate,Price)
)

The data looks something like this:

AssetId    EffectiveDate    Price
-------    -------------    -----
      1       2012-01-11     1.21
      1       2012-01-12     1.22
      2       2012-01-11     3.55
      2       2012-01-12     3.60
      3       2012-01-04     5.15
      3       2012-01-11     5.14

To query for the effective price of an AssetId is simple, but it takes a non-trivial amount of time to calculate.

It is ideal to store the data physically, so that only data changes to dbo.AssetPrice requires a recalculation of the effective price. I believe I cannot create an indexed view because the pertinent aggregate functions are not allowed in an indexed view.

How do I tune the table to retrieve the effective price (most recent price) very quickly?

  • 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-28T06:03:23+00:00Added an answer on May 28, 2026 at 6:03 am

    Basically you can use two different approaches:

    • Alter your table schema to include an interval. In this case, you need to store start AND end date to determine your effective period. With that, you just need to use a simple BETWEEN to get your desired price. You could also to add a non-clustered index on start and end dates and AssetId for optimal performance. By default, you could to add an end date as ‘9999-12-31’ and, every time an asset have a new price, you end current period and starts a new one. I (personally) prefer this option.

    • Stick with this schema and create an non-clustered index on EffectiveDate and AssetId. You’ll need to build an subselect to get max date for assets with effective date less than your desired date, like this:

    .

    CREATE INDEX    IX_AssetPrice_EffectiveDate
                    ON AssetPrice (EffectiveDate, AssetId) INCLUDE (Price)
    DECLARE @AssetId int = NULL, @EffectiveDate datetime = '2012-01-11'
    SELECT  AssetPrice.AssetId, AssetPrice.Price, AssetPrice.EffectiveDate
    FROM    AssetPrice
    JOIN    (
                SELECT  AssetId, MAX(EffectiveDate) EffectiveDate
                FROM    AssetPrice
                WHERE   EffectiveDate <= @EffectiveDate AND
                        (AssetId = @AssetId OR @AssetId IS NULL)
                GROUP BY AssetId
            ) Effective
            ON  AssetPrice.AssetId = Effective.AssetId AND
                AssetPrice.EffectiveDate = Effective.EffectiveDate
    WHERE   (AssetPrice.AssetId = @AssetId OR @AssetId IS NULL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2D image randomly and sparsely scattered with pixels. given a point
I have a set of point (x,y) on a 2d plane. Given a point
What I want to achieve is the following: At any given point in time,
Any given point of time, how can i get the memory size utilized by
I have one table that stores values with a point in time: CREATE TABLE
I'm trying to find rows which are within ____meters from the given point. THis
Given a point such as (0, 0, 0) and a vector like (x, y,
Given a point (pX, pY) and a circle with a known center (cX,cY) and
For given floating point numbers x and a , I would like to compute
Given a floating point number, I'm looking to get a String representation of a

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.