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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:59:20+00:00 2026-06-05T17:59:20+00:00

I have this table Test as Id, SomeValue, SomeText contains about a mill records,

  • 0

I have this table Test as Id, SomeValue, SomeText contains about a mill records, I altered the table to

ALTER TABLE Test
ADD ComputedColFloat FLOAT

all are set to null, fine! what I want is that for each row, the value of ComputedColFloat should be set to sum of values in column SomeValue upto that row. (The values in SomeValue are computed using RAND()!)

Say, if before adding the column, first five rows are

Id    SomeValue    SomeText
1     .91          text
2     .34          text
3     .52          text
4     .11          text
5     .68          text

what I want is to write a query that would update the table and set the added column to reflect the values as

Id    SomeValue    SomeText    ComputedColFloat
1     .91          text        .91   // .91
2     .34          text        1.25  // .91 + .34
3     .52          text        1.77  // .91 + .34 + .52
4     .11          text        1.88  // .91 + .34 + .52 + .11
5     .68          text        2.56  // .91 + .34 + .52 + .11 + .68 

I am using sql server 2008, and would prefer to do this from SSMS not from visual studio by C# or anything! (In C# in VS, I could loop, find the sum and then write a query that would update the records, but that’s not what I need, I need to do it from SSMS)
Also, if there are more than 1 way to do this, I would like to know what would be best performance wise, as I have about a mill records, I don’t wanna wait up forever! 🙁

  • 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-05T17:59:21+00:00Added an answer on June 5, 2026 at 5:59 pm

    You can create cursor for your table and update each row.

            DECLARE CUR_TEST CURSOR LOCAL For Select ID,SomeValue From test ORDER BY ID ASC
            DECLARE @TOTALSUM FLOAT
                        DECLARE @ID INT
            DECLARE @SOMEMVALUE FLOAT
            OPEN CUR_LOCAL
            SET @TOTALSUM=0
            SET @SOMEVALUE=0
            FETCH CUR_LOCAL INTO @ID,@SOMEVALUE
            WHILE @@FETCH_STATUS = 0 
            BEGIN
                SET @TOTALSUM=@TOTALSUM + @SOMEVALUE
                Update TEST SET ComputedColFloat =@TOTALSUM Where ID=@ID
                FETCH CUR_LOCAL INTO @ID,@SOMEVALUE
            END
            CLOSE CUR_LOCAL
            DEALLOCATE CUR_LOCAL
    

    Before executing take a copy of your table to verify

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

Sidebar

Related Questions

I have a table which stores test results like this: user | score |
I have this test table with one row entry and 2 indexes, the first
I have this database which contains a varchar. I want to know which records
I have a table that looks like this: CREATE TABLE [Test].[dbo].[MyTest] ( [Id] INT
Well lets say i have this <table class=infoBox> <tr> <td> test </td> <td> <table>
I have a test table like this CREATE TABLE #temp ( rid INT IDENTITY
I have this in my table model called Table $test = $this->find('first', array( 'conditions'
I have a table like this: create table `test` ( `id` bigint(20) NOT NULL
I have this table under user_name='high' function_description : akram is in a date test
i have this table test : date tid 1315976558 6224576 1315981082 6224576 1315976486 6224576

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.