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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:04:22+00:00 2026-06-13T18:04:22+00:00

Given the starting value @pStartingValue and a table which contains rorDate and ror what

  • 0

Given the starting value @pStartingValue and a table which contains rorDate and ror what is the most efficient way to get the NAV at each date using just TSQL?

This mathematically trivial, and simple in code. I have a naive SQL implementation currently that relies on cursors.

On the first date, the NAV is @pStartingValue * ror
On every subsequent date, it’s the previously calculated nav * ror or it’s @pStartingValue * every previous ror

How would you efficiently do this only in MSSQL2005+?

DECLARE @rorDate DATE
DECLARE @getDate CURSOR
DECLARE @lastNAV as DECIMAL(19,7)
DECLARE @datedRoR as float
DECLARE @NAVTotals TABLE
(
  NAV DECIMAL(19,7),
  navDate DATE
)


SET @lastNAV = 100

SET @getDate = CURSOR FOR
    SELECT 
        p.[DATE]
    FROM 
        performance p 
    ORDER BY 
        p.[DATE]

OPEN @getDate
FETCH NEXT
FROM @getDate INTO @rorDate
WHILE @@FETCH_STATUS = 0
BEGIN

SELECT 
    @datedRoR = b.finalNetReturn 
FROM 
    performance b 
WHERE 
    b.date = @rorDate

INSERT INTO @NAVTotals (NAV, navDate)
  VALUES (@lastNAV * (1 + @datedRoR), @rorDate)

SELECT 
    @lastNAV = c.NAV 
FROM 
    @NAVTotals c 
WHERE 
    c.navDate = @rorDate  


FETCH NEXT
FROM @getDate INTO @rorDate
END
CLOSE @getDate
DEALLOCATE @getDate

select * from @NAVTotals
  • 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-13T18:04:23+00:00Added an answer on June 13, 2026 at 6:04 pm

    You’ll have to do some testing to see if the performance improves but this is a way to do that same thing without using a cursor. It’s untested so you’ll want to make sure to test it. I also cast b.finalNetReturn as a float, if it’s already a float you can remove that part.

    DECLARE @lastNAV as DECIMAL(19,7)
    
    SET @lastNAV = 100    
    
    DECLARE @NAVTotals TABLE
    (
      NAV DECIMAL(19,7),
      navDate DATE
    );
    
    INSERT INTO @NAVTotals (navDate) 
       SELECT [DATE]
        FROM performance
        ORDER BY [DATE] ASC;
    
    UPDATE NT
    SET @lastNAV = Nav = (@lastNAV * (1.0 +
     (Cast((SELECT b.finalNetReturn 
            FROM performance b 
            WHERE b.date = NT.navDate) AS FLOAT)))) 
    FROM @NAVTotals NT;
    
    SELECT * FROM @NAVTotals ORDER BY navDate;
    

    By dropping the lastNAV variable into the update statement you can update both. It works similar to:

    a = a + 1
    

    There is an example of this same approach here. Including some good numbers that compare the efficiency of the approach to other approaches such as cursors.

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

Sidebar

Related Questions

Given a starting List<Foo> , what is the most concise way to determine if
Given an NSMutableArray of dynamic CGPoint s, what is the fastest and most efficient
I have a table which contains the following columns and I am trying to
Overview This is the scenario: I'm given a value which represents a portion of
a grid of NxN is given. each point is assigned a value say num
Given: alphabet = ['a','b','c',...,'z'] i want python to enumerate every combination (starting from 1
Given D discs, P poles, and the initial starting positions for the disks, and
Given a certain date, I want to set the value of a cell with
Given a MySQL table of real estate data, I would like to generate a
I need to know column name of a spread sheet with a given starting

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.