Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Adding column values

Adding column values

Scheduled Pinned Locked Moved Database
databasehelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yuvachandra
    wrote on last edited by
    #1

    Hi All! i have column1 which has some values in it. i want column2 to calculate the sum of the values in column1 in each cell as shown below: CL1 CL2 10 10 25 35 32 67 12 79 56 135 what is the query i need to write in order to acheive this.pl help me out.thanking in advance!!!

    C E 2 Replies Last reply
    0
    • Y yuvachandra

      Hi All! i have column1 which has some values in it. i want column2 to calculate the sum of the values in column1 in each cell as shown below: CL1 CL2 10 10 25 35 32 67 12 79 56 135 what is the query i need to write in order to acheive this.pl help me out.thanking in advance!!!

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Since a databases work on the concept of sets of data there is no intrinsic order in which the data exists. The implementation of the database software may make it appear that data is in a certain order, but that cannot be relied upon. In order to do what you want, you must first find a way to determine order. That might be through a primary key you already have, but didn't mention, or the creation of a new column that defines the order of the rows.


      Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      1 Reply Last reply
      0
      • Y yuvachandra

        Hi All! i have column1 which has some values in it. i want column2 to calculate the sum of the values in column1 in each cell as shown below: CL1 CL2 10 10 25 35 32 67 12 79 56 135 what is the query i need to write in order to acheive this.pl help me out.thanking in advance!!!

        E Offline
        E Offline
        Expert Coming
        wrote on last edited by
        #3

        Ok, actually you can do this very easily. Simply use a reader to read all the values in column 1 and add them to the same variable. Then add the value of the new insert to that same variable. That variable will be you value for column 2. I can explain better if you don't understand.

        The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.

        C 1 Reply Last reply
        0
        • E Expert Coming

          Ok, actually you can do this very easily. Simply use a reader to read all the values in column 1 and add them to the same variable. Then add the value of the new insert to that same variable. That variable will be you value for column 2. I can explain better if you don't understand.

          The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          ExpertComing wrote:

          Ok, actually you can do this very easily. Simply use a reader to read all the values in column 1 and add them to the same variable. Then add the value of the new insert to that same variable.

          You haven't taken into consideration the order of the rows. The OP has given no indication of how he determines the order. So, how do you know you are reading the rows in the correct order? Remembers any order that the rows appear in the result set are merely a quirk of the implementation and not guaranteed.


          Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          E 2 Replies Last reply
          0
          • C Colin Angus Mackay

            ExpertComing wrote:

            Ok, actually you can do this very easily. Simply use a reader to read all the values in column 1 and add them to the same variable. Then add the value of the new insert to that same variable.

            You haven't taken into consideration the order of the rows. The OP has given no indication of how he determines the order. So, how do you know you are reading the rows in the correct order? Remembers any order that the rows appear in the result set are merely a quirk of the implementation and not guaranteed.


            Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            E Offline
            E Offline
            Expert Coming
            wrote on last edited by
            #5

            He is looking for a sum. With a addition(sum) order doesn't matter. 2+1=3 1+2=3

            The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.

            1 Reply Last reply
            0
            • C Colin Angus Mackay

              ExpertComing wrote:

              Ok, actually you can do this very easily. Simply use a reader to read all the values in column 1 and add them to the same variable. Then add the value of the new insert to that same variable.

              You haven't taken into consideration the order of the rows. The OP has given no indication of how he determines the order. So, how do you know you are reading the rows in the correct order? Remembers any order that the rows appear in the result set are merely a quirk of the implementation and not guaranteed.


              Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              E Offline
              E Offline
              Expert Coming
              wrote on last edited by
              #6

              Oh, I understand what you mean now. Let me think about how to do it, I have an idea but I want to think about it to make sure that it will work.

              The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups