Group by sum based on under group in SQL Server












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 9 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 9 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 9 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 9 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

          Liste der Baudenkmale in Friedland (Mecklenburg)

          Single-Malt-Whisky

          Czorneboh