Group by sum based on under group in SQL ServerSQL Server Partitioning - what to use for partition key?How to...

How can I differentiate duration vs starting time

Real Analysis: Provide example of two Series that....

Why don't you get burned by the wood benches in a sauna?

Can a Way of Shadow Monk use Shadow Step to teleport to a dark ceiling and then body slam another creature?

How to deal with an underperforming subordinate?

What does an unprocessed RAW file look like?

How to know you are over-explaining and oversimplifying a subject?

Crack the bank account's password!

Buying a "Used" Router

Why don't programs completely uninstall (remove all their files) when I remove them?

Can a planet be tidally unlocked?

What is the reward?

Did ancient Germans take pride in leaving the land untouched?

Cartoon in which kids compete by fighting as monsters or creatures with special powers in a virtual world

Reason for small-valued feedback resistors in low noise Op Amp

Isn't a semicolon (';') needed after a function declaration in C++?

How do I purchase a drop bar bike that will be converted to flat bar?

Can someone explain what a key is?

Partial derivative with respect to three variables

How do I fight with Heavy Armor as a Wizard with Tenser's Transformation?

Do the speed limit reductions due to pollution also apply to electric cars in France?

How do I break down the math symbols in this equation

Including proofs of known theorems in master's thesis

How can I deal with my coworker having zero social awareness?



Group by sum based on under group in SQL Server


SQL Server Partitioning - what to use for partition key?How to recursively find gaps where 90 days passed, between rowsGrouping Data Using Joined Tables with Certain Distinct ValuesDisplay Total under name column and sum of amount under sal columnCreate a view showing total minutes per customer per month and change from previous monthHow to create sums/counts of grouped items over multiple tablesSelect command returning different column valuesSum by Implicit GroupIterating through a record set and selecting certain recordsSQL Query :Is it possible to count / group based on date with a sum over the group













0

















--TestData
declare @table table (groupname varchar(50),
credit numeric(18,2),
debit numeric(18,2),
drcreffect varchar(50),
undergroup varchar(50)
)

declare @table1 table (groupname varchar(50),
credit numeric(18,2),
debit numeric(18,2),
drcreffect varchar(50),
undergroup varchar(50)
)

insert into @table
values
('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase')


--Query
SELECT
RN = ROW_NUMBER() OVER(ORDER BY groupname),
undergroup,
groupname,
credit+debit Amt,
LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
FROM
(
SELECT DISTINCT
groupname,
SUM(credit) OVER(PARTITION BY groupname) AS Credit,
SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
undergroup
FROM @table
)X


this one my table data



enter image description here



I want output based on Undergroup with sum on group on last rows



enter image description here










share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0

















    --TestData
    declare @table table (groupname varchar(50),
    credit numeric(18,2),
    debit numeric(18,2),
    drcreffect varchar(50),
    undergroup varchar(50)
    )

    declare @table1 table (groupname varchar(50),
    credit numeric(18,2),
    debit numeric(18,2),
    drcreffect varchar(50),
    undergroup varchar(50)
    )

    insert into @table
    values
    ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
    ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
    ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
    ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
    ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase')


    --Query
    SELECT
    RN = ROW_NUMBER() OVER(ORDER BY groupname),
    undergroup,
    groupname,
    credit+debit Amt,
    LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
    FROM
    (
    SELECT DISTINCT
    groupname,
    SUM(credit) OVER(PARTITION BY groupname) AS Credit,
    SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
    undergroup
    FROM @table
    )X


    this one my table data



    enter image description here



    I want output based on Undergroup with sum on group on last rows



    enter image description here










    share|improve this question
















    bumped to the homepage by Community 10 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0










      --TestData
      declare @table table (groupname varchar(50),
      credit numeric(18,2),
      debit numeric(18,2),
      drcreffect varchar(50),
      undergroup varchar(50)
      )

      declare @table1 table (groupname varchar(50),
      credit numeric(18,2),
      debit numeric(18,2),
      drcreffect varchar(50),
      undergroup varchar(50)
      )

      insert into @table
      values
      ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
      ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
      ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
      ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
      ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase')


      --Query
      SELECT
      RN = ROW_NUMBER() OVER(ORDER BY groupname),
      undergroup,
      groupname,
      credit+debit Amt,
      LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
      FROM
      (
      SELECT DISTINCT
      groupname,
      SUM(credit) OVER(PARTITION BY groupname) AS Credit,
      SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
      undergroup
      FROM @table
      )X


      this one my table data



      enter image description here



      I want output based on Undergroup with sum on group on last rows



      enter image description here










      share|improve this question


















      --TestData
      declare @table table (groupname varchar(50),
      credit numeric(18,2),
      debit numeric(18,2),
      drcreffect varchar(50),
      undergroup varchar(50)
      )

      declare @table1 table (groupname varchar(50),
      credit numeric(18,2),
      debit numeric(18,2),
      drcreffect varchar(50),
      undergroup varchar(50)
      )

      insert into @table
      values
      ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
      ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
      ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
      ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
      ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase')


      --Query
      SELECT
      RN = ROW_NUMBER() OVER(ORDER BY groupname),
      undergroup,
      groupname,
      credit+debit Amt,
      LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
      FROM
      (
      SELECT DISTINCT
      groupname,
      SUM(credit) OVER(PARTITION BY groupname) AS Credit,
      SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
      undergroup
      FROM @table
      )X


      this one my table data



      enter image description here



      I want output based on Undergroup with sum on group on last rows



      enter image description here







      sql-server






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 29 '18 at 10:36









      IT WeiHan

      1233




      1233










      asked Jun 29 '18 at 5:58









      alpesh ramanialpesh ramani

      43




      43





      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          you can try use case when SumValue < -1 then -1 * SumValue else SumValue emd



          --TestData
          declare @table table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          declare @table1 table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          insert into @table
          values
          ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
          ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
          ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
          ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
          ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase');


          --Query
          with CTE as (
          SELECT
          RN = ROW_NUMBER() OVER(ORDER BY groupname),
          undergroup,
          groupname,
          credit+debit Amt,
          LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
          FROM
          (
          SELECT DISTINCT
          groupname,
          SUM(credit) OVER(PARTITION BY groupname) AS Credit,
          SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
          undergroup
          FROM @table
          )X
          )
          select
          RN,
          undergroup,
          groupname,
          case when Amt < 0 then -1*Amt else Amt end as Amt,
          case when Total < 0 then -1*Total else Total end as Total
          from CTE


          Result:



          +----+---------------+-----------------+---------+--------+
          | RN | undergroup | groupname | Amt | Total |
          +----+---------------+-----------------+---------+--------+
          | 1 | Opening Stock | Opening Stock | 700.00 | 700.00 |
          +----+---------------+-----------------+---------+--------+
          | 2 | Purchase | Purchase | 7500.00 | 0.00 |
          +----+---------------+-----------------+---------+--------+
          | 3 | Purchase | Purchase Return | 7200.00 | 300.00 |
          +----+---------------+-----------------+---------+--------+




          Demo Link






          share|improve this answer


























          • ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

            – alpesh ramani
            Jun 29 '18 at 7:07











          • not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

            – alpesh ramani
            Jun 29 '18 at 8:58











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdba.stackexchange.com%2fquestions%2f210933%2fgroup-by-sum-based-on-under-group-in-sql-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          you can try use case when SumValue < -1 then -1 * SumValue else SumValue emd



          --TestData
          declare @table table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          declare @table1 table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          insert into @table
          values
          ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
          ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
          ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
          ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
          ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase');


          --Query
          with CTE as (
          SELECT
          RN = ROW_NUMBER() OVER(ORDER BY groupname),
          undergroup,
          groupname,
          credit+debit Amt,
          LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
          FROM
          (
          SELECT DISTINCT
          groupname,
          SUM(credit) OVER(PARTITION BY groupname) AS Credit,
          SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
          undergroup
          FROM @table
          )X
          )
          select
          RN,
          undergroup,
          groupname,
          case when Amt < 0 then -1*Amt else Amt end as Amt,
          case when Total < 0 then -1*Total else Total end as Total
          from CTE


          Result:



          +----+---------------+-----------------+---------+--------+
          | RN | undergroup | groupname | Amt | Total |
          +----+---------------+-----------------+---------+--------+
          | 1 | Opening Stock | Opening Stock | 700.00 | 700.00 |
          +----+---------------+-----------------+---------+--------+
          | 2 | Purchase | Purchase | 7500.00 | 0.00 |
          +----+---------------+-----------------+---------+--------+
          | 3 | Purchase | Purchase Return | 7200.00 | 300.00 |
          +----+---------------+-----------------+---------+--------+




          Demo Link






          share|improve this answer


























          • ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

            – alpesh ramani
            Jun 29 '18 at 7:07











          • not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

            – alpesh ramani
            Jun 29 '18 at 8:58
















          0














          you can try use case when SumValue < -1 then -1 * SumValue else SumValue emd



          --TestData
          declare @table table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          declare @table1 table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          insert into @table
          values
          ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
          ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
          ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
          ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
          ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase');


          --Query
          with CTE as (
          SELECT
          RN = ROW_NUMBER() OVER(ORDER BY groupname),
          undergroup,
          groupname,
          credit+debit Amt,
          LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
          FROM
          (
          SELECT DISTINCT
          groupname,
          SUM(credit) OVER(PARTITION BY groupname) AS Credit,
          SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
          undergroup
          FROM @table
          )X
          )
          select
          RN,
          undergroup,
          groupname,
          case when Amt < 0 then -1*Amt else Amt end as Amt,
          case when Total < 0 then -1*Total else Total end as Total
          from CTE


          Result:



          +----+---------------+-----------------+---------+--------+
          | RN | undergroup | groupname | Amt | Total |
          +----+---------------+-----------------+---------+--------+
          | 1 | Opening Stock | Opening Stock | 700.00 | 700.00 |
          +----+---------------+-----------------+---------+--------+
          | 2 | Purchase | Purchase | 7500.00 | 0.00 |
          +----+---------------+-----------------+---------+--------+
          | 3 | Purchase | Purchase Return | 7200.00 | 300.00 |
          +----+---------------+-----------------+---------+--------+




          Demo Link






          share|improve this answer


























          • ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

            – alpesh ramani
            Jun 29 '18 at 7:07











          • not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

            – alpesh ramani
            Jun 29 '18 at 8:58














          0












          0








          0







          you can try use case when SumValue < -1 then -1 * SumValue else SumValue emd



          --TestData
          declare @table table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          declare @table1 table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          insert into @table
          values
          ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
          ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
          ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
          ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
          ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase');


          --Query
          with CTE as (
          SELECT
          RN = ROW_NUMBER() OVER(ORDER BY groupname),
          undergroup,
          groupname,
          credit+debit Amt,
          LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
          FROM
          (
          SELECT DISTINCT
          groupname,
          SUM(credit) OVER(PARTITION BY groupname) AS Credit,
          SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
          undergroup
          FROM @table
          )X
          )
          select
          RN,
          undergroup,
          groupname,
          case when Amt < 0 then -1*Amt else Amt end as Amt,
          case when Total < 0 then -1*Total else Total end as Total
          from CTE


          Result:



          +----+---------------+-----------------+---------+--------+
          | RN | undergroup | groupname | Amt | Total |
          +----+---------------+-----------------+---------+--------+
          | 1 | Opening Stock | Opening Stock | 700.00 | 700.00 |
          +----+---------------+-----------------+---------+--------+
          | 2 | Purchase | Purchase | 7500.00 | 0.00 |
          +----+---------------+-----------------+---------+--------+
          | 3 | Purchase | Purchase Return | 7200.00 | 300.00 |
          +----+---------------+-----------------+---------+--------+




          Demo Link






          share|improve this answer















          you can try use case when SumValue < -1 then -1 * SumValue else SumValue emd



          --TestData
          declare @table table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          declare @table1 table (groupname varchar(50),
          credit numeric(18,2),
          debit numeric(18,2),
          drcreffect varchar(50),
          undergroup varchar(50)
          )

          insert into @table
          values
          ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'),
          ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'),
          ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'),
          ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'),
          ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase');


          --Query
          with CTE as (
          SELECT
          RN = ROW_NUMBER() OVER(ORDER BY groupname),
          undergroup,
          groupname,
          credit+debit Amt,
          LAG(debit, 1,0) OVER(PARTITION BY undergroup ORDER BY undergroup)+credit AS Total
          FROM
          (
          SELECT DISTINCT
          groupname,
          SUM(credit) OVER(PARTITION BY groupname) AS Credit,
          SUM(debit*-1) OVER(PARTITION BY groupname) AS debit,
          undergroup
          FROM @table
          )X
          )
          select
          RN,
          undergroup,
          groupname,
          case when Amt < 0 then -1*Amt else Amt end as Amt,
          case when Total < 0 then -1*Total else Total end as Total
          from CTE


          Result:



          +----+---------------+-----------------+---------+--------+
          | RN | undergroup | groupname | Amt | Total |
          +----+---------------+-----------------+---------+--------+
          | 1 | Opening Stock | Opening Stock | 700.00 | 700.00 |
          +----+---------------+-----------------+---------+--------+
          | 2 | Purchase | Purchase | 7500.00 | 0.00 |
          +----+---------------+-----------------+---------+--------+
          | 3 | Purchase | Purchase Return | 7200.00 | 300.00 |
          +----+---------------+-----------------+---------+--------+




          Demo Link







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 29 '18 at 7:08

























          answered Jun 29 '18 at 7:02









          IT WeiHanIT WeiHan

          1233




          1233













          • ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

            – alpesh ramani
            Jun 29 '18 at 7:07











          • not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

            – alpesh ramani
            Jun 29 '18 at 8:58



















          • ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

            – alpesh ramani
            Jun 29 '18 at 7:07











          • not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

            – alpesh ramani
            Jun 29 '18 at 8:58

















          ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

          – alpesh ramani
          Jun 29 '18 at 7:07





          ans right.add new value& check closing record total insert into @table values ('Opening Stock', 200.00, 0.00, 'Dr', 'Opening Stock'), ('Opening Stock', 500.00, 0.00, 'Dr', 'Opening Stock'), ('Purchase', 0.00, 7500.00, 'Dr', 'Purchase'), ('Purchase Return', 7000.00, 0.00, 'Dr', 'Purchase'), ('Purchase Return', 200.00, 0.00, 'Dr', 'Purchase'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale', 0.00, 5000.00 ,'Dr', 'Sales'), ('Sale return', 200, .00 ,'Dr', 'Sales'), ('Closing Stock',0.00 ,1000,'Dr', 'Closing Stock');

          – alpesh ramani
          Jun 29 '18 at 7:07













          not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

          – alpesh ramani
          Jun 29 '18 at 8:58





          not + or - value actuall you hunderstand some thing wrong i have put some other result please check this result with your query and check total value in gropwise

          – alpesh ramani
          Jun 29 '18 at 8:58


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • 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%2fdba.stackexchange.com%2fquestions%2f210933%2fgroup-by-sum-based-on-under-group-in-sql-server%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

          ORA-01691 (unable to extend lob segment) even though my tablespace has AUTOEXTEND onORA-01692: unable to...

          Always On Availability groups resolving state after failover - Remote harden of transaction...

          Circunscripción electoral de Guipúzcoa Referencias Menú de navegaciónLas claves del sistema electoral en...