Group by sum based on under group in SQL ServerSQL Server Partitioning - what to use for partition key?How to...
Is there redundancy between a US Passport Card and an Enhanced Driver's License?
Is the UK legally prevented from having another referendum on Brexit?
Short story about a man betting a group he could tell a story, and one of them would disappear and the others would not notice
Can someone explain European graduate programs in STEM fields?
What is an efficient way to digitize a family photo collection?
How do I fight with Heavy Armor as a Wizard with Tenser's Transformation?
Can someone explain what a key is?
Need help now with power steering
Converting numbers to words - Python
Is it possible to narrate a novel in a faux-historical style without alienating the reader?
What does "don't have a baby" imply or mean in this sentence?
How do I purchase a drop bar bike that will be converted to flat bar?
Is there any danger of my neighbor having my wife's signature?
Including proofs of known theorems in master's thesis
Did ancient Germans take pride in leaving the land untouched?
If I tried and failed to start my own business, how do I apply for a job without job experience?
Why does this quiz question say that protons and electrons do not combine to form neutrons?
Is layered encryption more secure than long passwords?
Boss asked me to sign a resignation paper without a date on it along with my new contract
Why does a single AND gate need 60 transistors?
How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?
How can I prep for the Curse of Strahd adventure effectively?
What could cause an entire planet of humans to become aphasic?
Why is Shelob considered evil?
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
--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
I want output based on Undergroup with sum on group on last rows
sql-server
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.
add a comment |
--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
I want output based on Undergroup with sum on group on last rows
sql-server
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.
add a comment |
--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
I want output based on Undergroup with sum on group on last rows
sql-server
--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
I want output based on Undergroup with sum on group on last rows
sql-server
sql-server
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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