Total Sum of two columns and show in the third ColumnAdd a column with a default value to an existing table in SQL ServerSQLite - UPSERT *not* INSERT or REPLACESELECT DISTINCT on one columnSQL update query using joinsHow can I get column names from a table in SQL Server?SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?SQL select only rows with max value on a columnReset identity seed after deleting records in SQL ServerHow to sum two column & save in database

What does this 7 mean above the f flat

Go Pregnant or Go Home

Is this Spell Mimic feat balanced?

Modify casing of marked letters

Are there any comparative studies done between Ashtavakra Gita and Buddhim?

How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?

Increase performance creating Mandelbrot set in python

Generic lambda vs generic function give different behaviour

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

What to do with wrong results in talks?

What is the oldest known work of fiction?

Is there a good way to store credentials outside of a password manager?

apt-get update is failing in debian

Can I use my Chinese passport to enter China after I acquired another citizenship?

Is there any reason not to eat food that's been dropped on the surface of the moon?

Coordinate position not precise

Should my PhD thesis be submitted under my legal name?

What is difference between behavior and behaviour

Why are on-board computers allowed to change controls without notifying the pilots?

Is a roofing delivery truck likely to crack my driveway slab?

Student evaluations of teaching assistants

Is exact Kanji stroke length important?

voltage of sounds of mp3files

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?



Total Sum of two columns and show in the third Column


Add a column with a default value to an existing table in SQL ServerSQLite - UPSERT *not* INSERT or REPLACESELECT DISTINCT on one columnSQL update query using joinsHow can I get column names from a table in SQL Server?SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?SQL select only rows with max value on a columnReset identity seed after deleting records in SQL ServerHow to sum two column & save in database













0















I have a Three columns in the SQL table,



I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.



This is my table structure



Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked









share|improve this question
























  • Do you want to select the sum or store the sum in the table?

    – juergen d
    Jan 15 '15 at 7:50











  • Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.

    – jarlh
    Jan 15 '15 at 7:50












  • @juergend I want to store the sum in the total column

    – user3755380
    Jan 15 '15 at 7:51












  • @jarlh: How can we do that ?

    – user3755380
    Jan 15 '15 at 7:51











  • Then you need triggers that update the column value if one of the other changes

    – juergen d
    Jan 15 '15 at 7:52















0















I have a Three columns in the SQL table,



I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.



This is my table structure



Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked









share|improve this question
























  • Do you want to select the sum or store the sum in the table?

    – juergen d
    Jan 15 '15 at 7:50











  • Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.

    – jarlh
    Jan 15 '15 at 7:50












  • @juergend I want to store the sum in the total column

    – user3755380
    Jan 15 '15 at 7:51












  • @jarlh: How can we do that ?

    – user3755380
    Jan 15 '15 at 7:51











  • Then you need triggers that update the column value if one of the other changes

    – juergen d
    Jan 15 '15 at 7:52













0












0








0








I have a Three columns in the SQL table,



I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.



This is my table structure



Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked









share|improve this question
















I have a Three columns in the SQL table,



I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.



This is my table structure



Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked






sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 15 '15 at 8:11









Sathyajith Bhat

16.2k2084117




16.2k2084117










asked Jan 15 '15 at 7:49







user3755380



















  • Do you want to select the sum or store the sum in the table?

    – juergen d
    Jan 15 '15 at 7:50











  • Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.

    – jarlh
    Jan 15 '15 at 7:50












  • @juergend I want to store the sum in the total column

    – user3755380
    Jan 15 '15 at 7:51












  • @jarlh: How can we do that ?

    – user3755380
    Jan 15 '15 at 7:51











  • Then you need triggers that update the column value if one of the other changes

    – juergen d
    Jan 15 '15 at 7:52

















  • Do you want to select the sum or store the sum in the table?

    – juergen d
    Jan 15 '15 at 7:50











  • Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.

    – jarlh
    Jan 15 '15 at 7:50












  • @juergend I want to store the sum in the total column

    – user3755380
    Jan 15 '15 at 7:51












  • @jarlh: How can we do that ?

    – user3755380
    Jan 15 '15 at 7:51











  • Then you need triggers that update the column value if one of the other changes

    – juergen d
    Jan 15 '15 at 7:52
















Do you want to select the sum or store the sum in the table?

– juergen d
Jan 15 '15 at 7:50





Do you want to select the sum or store the sum in the table?

– juergen d
Jan 15 '15 at 7:50













Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.

– jarlh
Jan 15 '15 at 7:50






Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.

– jarlh
Jan 15 '15 at 7:50














@juergend I want to store the sum in the total column

– user3755380
Jan 15 '15 at 7:51






@juergend I want to store the sum in the total column

– user3755380
Jan 15 '15 at 7:51














@jarlh: How can we do that ?

– user3755380
Jan 15 '15 at 7:51





@jarlh: How can we do that ?

– user3755380
Jan 15 '15 at 7:51













Then you need triggers that update the column value if one of the other changes

– juergen d
Jan 15 '15 at 7:52





Then you need triggers that update the column value if one of the other changes

– juergen d
Jan 15 '15 at 7:52












5 Answers
5






active

oldest

votes


















0














You can use comuted column for this:



CREATE TABLE [dbo].[Test](
[a] [INT] NULL,
[b] [INT] NULL,
[c] AS ([a]+[b])
) ON [PRIMARY]

GO

INSERT INTO dbo.Test
( a, b )
VALUES ( 1, -- a - int
2 -- b - int
)


SELECT * FROM dbo.Test

Results:
a b c
1 2 3





share|improve this answer























  • Thanks giorgi, it worked. Thats what I wanted

    – user3755380
    Jan 15 '15 at 8:05











  • Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

    – user3755380
    Jan 15 '15 at 8:32











  • @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

    – Pரதீப்
    Jan 15 '15 at 8:34












  • SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

    – Giorgi Nakeuri
    Jan 15 '15 at 8:35












  • @NoDisplayName: I think the issue is related to the same scenario if I guess..

    – user3755380
    Jan 15 '15 at 8:35


















3














There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:



SELECT
Id,
Col_A,
Col_B,
Col_A + Col_B AS Total
FROM tablename





share|improve this answer






























    0














    Here is my table where the colums are salary and variable.



    enter image description here



    Now i need the sum of basic and variable as total.
    Here is the query for that-



    select basic,variable,(basic+variable) as total from salary


    enter image description here






    share|improve this answer






























      0














      This is the given table:



      After performing the following query



      enter image description here



      or if you just want to display total:



      enter image description here






      share|improve this answer






























        -1














        Try the following -



        ALTER TABLE TABLENAME ADD colC AS ColA * ColB





        share|improve this answer
























          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27958801%2ftotal-sum-of-two-columns-and-show-in-the-third-column%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown
























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can use comuted column for this:



          CREATE TABLE [dbo].[Test](
          [a] [INT] NULL,
          [b] [INT] NULL,
          [c] AS ([a]+[b])
          ) ON [PRIMARY]

          GO

          INSERT INTO dbo.Test
          ( a, b )
          VALUES ( 1, -- a - int
          2 -- b - int
          )


          SELECT * FROM dbo.Test

          Results:
          a b c
          1 2 3





          share|improve this answer























          • Thanks giorgi, it worked. Thats what I wanted

            – user3755380
            Jan 15 '15 at 8:05











          • Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

            – user3755380
            Jan 15 '15 at 8:32











          • @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

            – Pரதீப்
            Jan 15 '15 at 8:34












          • SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

            – Giorgi Nakeuri
            Jan 15 '15 at 8:35












          • @NoDisplayName: I think the issue is related to the same scenario if I guess..

            – user3755380
            Jan 15 '15 at 8:35















          0














          You can use comuted column for this:



          CREATE TABLE [dbo].[Test](
          [a] [INT] NULL,
          [b] [INT] NULL,
          [c] AS ([a]+[b])
          ) ON [PRIMARY]

          GO

          INSERT INTO dbo.Test
          ( a, b )
          VALUES ( 1, -- a - int
          2 -- b - int
          )


          SELECT * FROM dbo.Test

          Results:
          a b c
          1 2 3





          share|improve this answer























          • Thanks giorgi, it worked. Thats what I wanted

            – user3755380
            Jan 15 '15 at 8:05











          • Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

            – user3755380
            Jan 15 '15 at 8:32











          • @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

            – Pரதீப்
            Jan 15 '15 at 8:34












          • SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

            – Giorgi Nakeuri
            Jan 15 '15 at 8:35












          • @NoDisplayName: I think the issue is related to the same scenario if I guess..

            – user3755380
            Jan 15 '15 at 8:35













          0












          0








          0







          You can use comuted column for this:



          CREATE TABLE [dbo].[Test](
          [a] [INT] NULL,
          [b] [INT] NULL,
          [c] AS ([a]+[b])
          ) ON [PRIMARY]

          GO

          INSERT INTO dbo.Test
          ( a, b )
          VALUES ( 1, -- a - int
          2 -- b - int
          )


          SELECT * FROM dbo.Test

          Results:
          a b c
          1 2 3





          share|improve this answer













          You can use comuted column for this:



          CREATE TABLE [dbo].[Test](
          [a] [INT] NULL,
          [b] [INT] NULL,
          [c] AS ([a]+[b])
          ) ON [PRIMARY]

          GO

          INSERT INTO dbo.Test
          ( a, b )
          VALUES ( 1, -- a - int
          2 -- b - int
          )


          SELECT * FROM dbo.Test

          Results:
          a b c
          1 2 3






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 15 '15 at 7:54









          Giorgi NakeuriGiorgi Nakeuri

          31.3k72556




          31.3k72556












          • Thanks giorgi, it worked. Thats what I wanted

            – user3755380
            Jan 15 '15 at 8:05











          • Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

            – user3755380
            Jan 15 '15 at 8:32











          • @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

            – Pரதீப்
            Jan 15 '15 at 8:34












          • SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

            – Giorgi Nakeuri
            Jan 15 '15 at 8:35












          • @NoDisplayName: I think the issue is related to the same scenario if I guess..

            – user3755380
            Jan 15 '15 at 8:35

















          • Thanks giorgi, it worked. Thats what I wanted

            – user3755380
            Jan 15 '15 at 8:05











          • Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

            – user3755380
            Jan 15 '15 at 8:32











          • @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

            – Pரதீப்
            Jan 15 '15 at 8:34












          • SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

            – Giorgi Nakeuri
            Jan 15 '15 at 8:35












          • @NoDisplayName: I think the issue is related to the same scenario if I guess..

            – user3755380
            Jan 15 '15 at 8:35
















          Thanks giorgi, it worked. Thats what I wanted

          – user3755380
          Jan 15 '15 at 8:05





          Thanks giorgi, it worked. Thats what I wanted

          – user3755380
          Jan 15 '15 at 8:05













          Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

          – user3755380
          Jan 15 '15 at 8:32





          Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records. 1+ 1+ 1+ ... and at the last I have to show the total of these 10 records, how to show that ?

          – user3755380
          Jan 15 '15 at 8:32













          @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

          – Pரதீப்
          Jan 15 '15 at 8:34






          @Nadeem - You need to ask a new question and also you should show some effort to solve your problem

          – Pரதீப்
          Jan 15 '15 at 8:34














          SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

          – Giorgi Nakeuri
          Jan 15 '15 at 8:35






          SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters

          – Giorgi Nakeuri
          Jan 15 '15 at 8:35














          @NoDisplayName: I think the issue is related to the same scenario if I guess..

          – user3755380
          Jan 15 '15 at 8:35





          @NoDisplayName: I think the issue is related to the same scenario if I guess..

          – user3755380
          Jan 15 '15 at 8:35













          3














          There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:



          SELECT
          Id,
          Col_A,
          Col_B,
          Col_A + Col_B AS Total
          FROM tablename





          share|improve this answer



























            3














            There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:



            SELECT
            Id,
            Col_A,
            Col_B,
            Col_A + Col_B AS Total
            FROM tablename





            share|improve this answer

























              3












              3








              3







              There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:



              SELECT
              Id,
              Col_A,
              Col_B,
              Col_A + Col_B AS Total
              FROM tablename





              share|improve this answer













              There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:



              SELECT
              Id,
              Col_A,
              Col_B,
              Col_A + Col_B AS Total
              FROM tablename






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 15 '15 at 7:54









              AlanAlan

              2,6272816




              2,6272816





















                  0














                  Here is my table where the colums are salary and variable.



                  enter image description here



                  Now i need the sum of basic and variable as total.
                  Here is the query for that-



                  select basic,variable,(basic+variable) as total from salary


                  enter image description here






                  share|improve this answer



























                    0














                    Here is my table where the colums are salary and variable.



                    enter image description here



                    Now i need the sum of basic and variable as total.
                    Here is the query for that-



                    select basic,variable,(basic+variable) as total from salary


                    enter image description here






                    share|improve this answer

























                      0












                      0








                      0







                      Here is my table where the colums are salary and variable.



                      enter image description here



                      Now i need the sum of basic and variable as total.
                      Here is the query for that-



                      select basic,variable,(basic+variable) as total from salary


                      enter image description here






                      share|improve this answer













                      Here is my table where the colums are salary and variable.



                      enter image description here



                      Now i need the sum of basic and variable as total.
                      Here is the query for that-



                      select basic,variable,(basic+variable) as total from salary


                      enter image description here







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 14 '18 at 15:55









                      Debendra DashDebendra Dash

                      2,2911922




                      2,2911922





















                          0














                          This is the given table:



                          After performing the following query



                          enter image description here



                          or if you just want to display total:



                          enter image description here






                          share|improve this answer



























                            0














                            This is the given table:



                            After performing the following query



                            enter image description here



                            or if you just want to display total:



                            enter image description here






                            share|improve this answer

























                              0












                              0








                              0







                              This is the given table:



                              After performing the following query



                              enter image description here



                              or if you just want to display total:



                              enter image description here






                              share|improve this answer













                              This is the given table:



                              After performing the following query



                              enter image description here



                              or if you just want to display total:



                              enter image description here







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 3 '18 at 14:56









                              yellow_flash11yellow_flash11

                              177




                              177





















                                  -1














                                  Try the following -



                                  ALTER TABLE TABLENAME ADD colC AS ColA * ColB





                                  share|improve this answer





























                                    -1














                                    Try the following -



                                    ALTER TABLE TABLENAME ADD colC AS ColA * ColB





                                    share|improve this answer



























                                      -1












                                      -1








                                      -1







                                      Try the following -



                                      ALTER TABLE TABLENAME ADD colC AS ColA * ColB





                                      share|improve this answer















                                      Try the following -



                                      ALTER TABLE TABLENAME ADD colC AS ColA * ColB






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 8 at 9:54









                                      Tushar Walzade

                                      2,38131935




                                      2,38131935










                                      answered Mar 8 at 9:33









                                      TaiwoTaiwo

                                      1




                                      1



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27958801%2ftotal-sum-of-two-columns-and-show-in-the-third-column%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                                          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived