Hi
I have 2 tables
Purchase Table - ItemCode, Qty Recd
Issue Table - ItemCode, Qty Issued
I want to group Data by ItemCode and then display data like below
ItemCode Qty Recd Qty Issued Qty Balance
1 10 2 8
2 4 4
Thanks
Hi
I have 2 tables
Purchase Table - ItemCode, Qty Recd
Issue Table - ItemCode, Qty Issued
I want to group Data by ItemCode and then display data like below
ItemCode Qty Recd Qty Issued Qty Balance
1 10 2 8
2 4 4
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Oct 16, 2022, 10:14 AM EDT
Try the following query:
var total = from PT in context.PurchaseTable join IT in context.IssueTable on PT.ItemCode equals IT.ItemCode group T3 by new { PT.ItemCode } into g select new { ItemCode = PT.ItemCode, QtyRecd = g.Sum(t3 => PT.QtyRecd), QtyIssued = g.Sum(t3 => IT.QtyIssued), QtyBalance = g.Sum(t3 => PT.QtyRecd) - g.Sum(t3 => IT.QtyIssued) };Sachin SinghRank #66 · 26.2K reputationPosted Oct 16, 2022, 10:29 AM EDT
var res1= (from p in _context.Purchases join i in _context.Issues on p.ItemCode equals i.ItemCode select new { ItemCode=p.ItemCode, QtyRecd =p.QtyRecd, QtyIssued=i.QtyIssued }).ToList();public class MainVM { public int ItemCode {get;set;} public int QtyRecd {get;set;} public int QtyIssued {get;set;} public int QtyBalance {get;set;} }var resMain= (from a in res1 group a by ItemCode into g select new MainVM { ItemCode=g.Key, QtyRecd= (Int)Sum(x=>x.QtyRecd), QtyIssued=(int)Sum(x=>x.QtyIssued), QtyBalance=(Int)Sum(x=>x.QtyRecd)-(int)Sum(x=>x.QtyIssued) }).ToList();Ramco RamcoRank #462 · 5.4K reputationPosted Oct 16, 2022, 1:30 PM EDT
Hi Muhammad
It is giving error on context.view_details - could not find an implementation of the query pattern to source type table
var total = (from PT in context.View_Details join IT in context.View_DeliveryDetails on PT.ItemCode equals IT.ItemCode group T3 by new { PT.ItemCode } into g select new { ItemCode = PT.ItemCode, QtyRecd = g.Sum(t3 => PT.QtyRecd), QtyIssued = g.Sum(t3 => IT.QtyIssued), QtyBalance = g.Sum(t3 => PT.QtyRecd) - g.Sum(t3 => IT.QtyIssued) }Thanks