User Profile
Collapse
-
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL ServerThanks dear vijay6! that was exactly what I wanted. I'm really grateful -
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL ServerDear r035198x
I tried it your way:
Code:SELECT (SELECT sum(Quantity) AS QTY01 FROM VoucherTable WHERE VoucherType = '01' GROUP BY PartName, DLName), (SELECT sum(Quantity) AS QTY02 FROM VoucherTable WHERE VoucherType = '02' GROUP BY PartName, DLName), (SELECT sum(Quantity) AS QTY03 FROM VoucherTable WHERE VoucherType = '03' GROUP BY PartName, DLName), (SELECT sum(Quantity) AS QTY04 FROM VoucherTable WHERE VoucherType
Leave a comment:
-
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL Serverthank you dear r035198x! you're right about posting my own script. This is the script I used (forget about the VoucherDate):
Code:SELECT PartName, DLName, (SELECT sum(quantity) WHERE VoucherType = '01' GROUP BY PartName, DLName), (SELECT sum(quantity) WHERE VoucherType = '02' GROUP BY PartName, DLName), SELECT sum(quantity) WHERE VoucherType = '03' GROUP BY PartName, DLName) GROUP BY PartName, DLName
Leave a comment:
-
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL Serversorry about the last reply. texts all got mixed up, so I took a screenshot from the sets:
This is my dataset:
and I want to get this result set:
...Leave a comment:
-
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL ServerVchID||||VchTyp e| VchQty||PartNam e |DlName
001 |||||01 ||||| 10 |||||Book |||||David
002 |||||02 ||||| 5 |||||Pen |||||David
003 |||||01 ||||| 12 |||||Book |||||David
004 |||||02 ||||| 15 |||||Pen |||||David
005 |||||01 ||||| 30 |||||Pen |||||David
006 |||||02 ||||| 2 |||||Book |||||David
007 |||||01 ||||| 19 |||||Pen |||||David
008 |||||02 ||||| 16 |||||Book |||||David
009 |||||01...Leave a comment:
-
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL ServerVchID VchType VchQty PartName DlName
001 01 10 Book David
002 02 5 Pen David
003 01 12 Book David
004 02 15 Pen David
005 01 30 Pen David
006 02 2 Book David
007 01 19 Pen David
008 02 16 Book David
009 01 17...Leave a comment:
-
mehdi483 replied to Sum one field in different fields based on conditions on another field with group byin SQL ServerThanks for answering dear Rabbit.
I have attached the data set and result set in an excel file.
I hope those tables are clear enough. For every PartName-DlName combination, I want to get the sum of the quantities of vchtype=01 in one field and sum of the quantities of vchtype=02 in another field....Leave a comment:
-
mehdi483 started a topic Sum one field in different fields based on conditions on another field with group byin SQL ServerSum one field in different fields based on conditions on another field with group by
Hi! I'm a beginner user of mssql and I've been stuck in a report that I'm trying to make.
I have a table with fields like 'PartName', 'VoucherQuantit y', 'VoucherType', 'VoucherDate', and 'DLName'. I want to get the sum of 'VoucherQuantit y' and I want its results in different fields based on different values of 'VoucherType' (which for example can be 01, 02, 03, or 04) and I want the result to be grouped by 'PartName' AND 'DLName'. Obviously...
No activity results to display
Show More
Leave a comment: