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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:58:08+00:00 2026-05-15T13:58:08+00:00

I am trying to do some operation in column ‘Increment’ based on previous row

  • 0

I am trying to do some operation in column ‘Increment’ based on previous row record in column ‘Value’

e.g.

row_num| Period | Measure | Decay
1      | Jan 08 | 10      | 
2      | Feb 08 | 18      | 
3      | Mar 08 | 7       | 
4      | Apr 08 | 67      | 

i would like to update column ‘Decay’ based on a formula

row_num| Period | Measure| Decay
1      | Jan 08 | 10     | = 10             -> first value in 'Measures'
2      | Feb 08 | 18     | = 10*0.5+18 = 23 -> previous decay record *0.5 + current measure
3      | Mar 08 | 7      | = 23*0.5+7  = 18.5
4      | Apr 08 | 67     | = 18.5*0.5+67 = 76.25

would cursor be applicable here? how would the syntax be like?
thank you

  • 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-15T13:58:09+00:00Added an answer on May 15, 2026 at 1:58 pm

    Here’s a running example using a recursive CTE (also note that the arithmetic in your example is incorrect):

    -- SO3192010
    
    DECLARE @t AS TABLE (row_num int NOT NULL, Period varchar(6) NOT NULL, Measure float NOT NULL)
    INSERT INTO @t VALUES (1, 'Jan 08', 10)
        ,(2, 'Feb 08', 18)
        ,(3, 'Mar 08', 7)
        ,(4, 'Apr 08', 67)
    
    ;WITH r AS (
        SELECT t.*, Measure AS Decay
        FROM @t AS t
        WHERE t.row_num = 1
    
        UNION ALL
    
        SELECT t.*, r.Decay * 0.5 + t.Measure AS Decay
        FROM r
        INNER JOIN @t AS t
            ON t.row_num = r.row_num + 1
    )
    SELECT *
    FROM r
    ORDER BY row_num​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to do some operation with files the code goes like this, File
I'm trying to implement some basic linear algebra operations and one of these operations
I’m thinking about trying some development for the iPhone, is it possible to install
I'm trying some of the ASP.NET MVC tutorials and one of them has the
I'm a beginner C++ programmer, and to stretch my mind I've been trying some
I've started with ASP.NET MVC recently, reading blogs, tutorials, trying some routes, etc. Now,
I have just started learning Erlang and am trying out some Project Euler problems
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Hey having some trouble trying to maintain transparency on a png when i create
When trying to link some well established tools to my company's active directory, I

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.