Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sparrow37
Posting Yak Master
148 Posts |
Posted - 2014-12-14 : 04:05:25
|
I have following querySelect Date, Item_Code, SUM(In_Quantity) as In_Quantity, SUM(Issue_Quantity) as Issue_Quantity, (SUM(In_Quantity)-SUM(issue_Quantity)) as BalanceQty from(select tbl_add_product.Date as Date, tbl_add_product.Item_Code, tbl_add_product.In_Quantity, 0 as Issue_Quantity from tbl_add_productwhere Item_Code = 'pen' union ALLselect tbl_issue_product.Date as Date, tbl_issue_product.Item_Code, 0 as In_Quantity, Issue_Quantity from tbl_issue_productwhere Item_Code = 'pen') X group by Item_Code, Date which gives following result:**Date Item_Code In_Quantity Issue_Quanitity BalanceQty**2014-12-02 pen 100 0 1002014-12-03 pen 50 50 0I want to 100 in second row. the logic is that balance Qty from first row should be added to In_Qty so that when Issue_Quantity is subtracted from it, it gives BalanceQtyPlease suggest solution |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-14 : 08:23:34
|
Not sure what you mean by "I want to 100 in second row." Do you mean:1. I want two 100's in the second row?2. I want to see 100 in <which column?> in the second row?3. Something else?Can you also please post:1. Some input data2. THe results you expect from your query using that input data. |
|
|
|
|
|