Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9034291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:26:19+00:00 2026-06-16T08:26:19+00:00

Some background before asking my question. Im using sql compact, and i have two

  • 0

Some background before asking my question.

Im using sql compact, and i have two tables,
The first table (IssueEmp)

enter image description here

The second table (RecEmp)

enter image description here

 SqlCeDataAdapter adap = new SqlCeDataAdapter("SELECT * FROM RecEmp", cn);
            DataTable dat = new DataTable();
            DataSet receice = new DataSet();
            adap.Fill(receice);
            adap.Fill(dat);

 SqlCeDataAdapter adap1 = new SqlCeDataAdapter("SELECT * FROM IssueEmp", cn);
            DataTable dat1 = new DataTable();
            DataSet issue = new DataSet();
            adap1.Fill(issue);
            adap1.Fill(dat1);

Im performing a join between RecEmp and IssueEmp using linq

var res = from t1 in receice.Tables[0].AsEnumerable()

                      join t2 in issue.Tables[0].AsEnumerable()                                            
                         on new 
                         {
                             CNo = t1.Field<int>("CNo"),
                             Empid = t1.Field<int>("EmpID") 
                         } 
                         equals new 
                         {
                             CNo = t2.Field<int>("CNo"),
                             Empid = t2.Field<int>("EmpID") 
                         }                     
                      select new
                       {
                           SNo = t1.Field<int>("SNo"),
                           ChNo = t1.Field<int>("CNo"),
                           EmpID = t1.Field<int>("EmpID"),
                           DateIssued = t2.Field<DateTime>("Date"),                                                                               
                           RMIssued = t2.Field<string>("RMCode"),
                           QuantityIssued = t2.Field<double>("Quantity"),

                           DateReceived = t1.Field<DateTime>("Date"),
                           RMCodeReceived = t1.Field<string>("RMCode"),
                           QuantityReceived = t1.Field<double>("Quantity")

                       };

The output Im getting from the above linq query is

enter image description here

But I don’t know how to get the sum of issued quantity likewise the sum of received quantity, lastly the difference between the two sum as the diff. The required is below.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:26:20+00:00Added an answer on June 16, 2026 at 8:26 am

    Note:

    I´m a bit lazy so I didn´t use all the records you provided, only the first four records.

    Expected result:

    This is what I got:

    enter image description here

    The Linq query:

    var query = from d in data
               group d by new { d.DateIssued, d.EmpId, d.ChNo, d.DateReceived }
               into x
               select new {
                    Date = x.Key.DateIssued,
                    CNo = x.Key.ChNo,
                    EmpId=x.Key.EmpId,
                    CRi = x.Where(c=>c.RMIssued == "CR").Sum(c=>c.QuantityIssued),
                    SJi = x.Where(c=>c.RMIssued == "SJ").Sum(c=>c.QuantityIssued),
                    TTi = x.Where(c=>c.RMIssued == "TT").Sum(c=>c.QuantityIssued),
                    WRi = x.Where(c=>c.RMIssued == "WR").Sum(c=>c.QuantityIssued),
                    TotalIssued = x.Sum(c => c.QuantityIssued),
    
                    DateReceived = x.Key.DateReceived,
                    CRr = x.Where(c=>c.RMCodeReceived == "CR").Sum(c=>c.QuantityReceived),
                    SJr = x.Where(c=>c.RMCodeReceived == "SJ").Sum(c=>c.QuantityReceived),
                    TTr = x.Where(c=>c.RMCodeReceived == "TT").Sum(c=>c.QuantityReceived),
                    WRr = x.Where(c=>c.RMCodeReceived == "WR").Sum(c=>c.QuantityReceived),
                    TotalReceived = x.Sum(c => c.QuantityReceived),
    
                    Diff = x.Sum(c => c.QuantityIssued) - x.Sum(c => c.QuantityReceived)
                };
    

    Data used:

    And this is the set of data I used to test it:

    var data= new []{
        new { SNo= 9,  ChNo=5,  EmpId=81, DateIssued=dateIssued, RMIssued="SJ", QuantityIssued=30,   DateReceived=dateReceived, RMCodeReceived="SJ", QuantityReceived=20.3},
        new { SNo= 10, ChNo=5,  EmpId=81, DateIssued=dateIssued, RMIssued="SJ", QuantityIssued=30,   DateReceived=dateReceived, RMCodeReceived="CR", QuantityReceived=9.6},
        new { SNo= 11, ChNo=28, EmpId=82, DateIssued=dateIssued, RMIssued="TT", QuantityIssued=30.5, DateReceived=dateReceived, RMCodeReceived="TT", QuantityReceived=29},
        new { SNo= 12, ChNo=28, EmpId=82, DateIssued=dateIssued, RMIssued="WR", QuantityIssued=10,   DateReceived=dateReceived, RMCodeReceived="TT", QuantityReceived=29}
    };
    

    I recommed you use LinqPad to test it.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some background on the questions. I have never used ravedb before and I'm
First some background: I have a website using ASP.NET web forms + jQuery 1.6.4
First some background information: We have three environments for our EJB3 application: test, development
This has some lengthy background before the actual question, however, it bears some explaining
before I dive into the question here is some background information of what I
I have an Android Service that does some background processing on an image using
Let me give some background before I ask my question. I’m at a shop
I'm about to have to rewrite some rather old code using SQL Server's BULK
Let me pose a bit of background information before asking my question: I recently
My program does some network activity in a background thread. Before starting, it pops

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.