New to Linq to SQL and novice in SQL. First post so please be gentle.
I have something similar to the following table I am querying into a dataGridView based on a date range in C#.
HeatNumber ChargeNumber Weight DOB
1 1 500 8/26/15
1 2 3500 8/26/15
1 3 2200 8/26/15
2 1 2000 8/27/15
2 2 1100 8/27/15
var query = from SU in dct.GetTable<ScrapInCharge>()
where ((SU.DOB >= dateTimePicker2.Value.Date) &&
(SU.DOB <= dateTimePicker1.Value.Date))
orderby SU.HeatNumber descending
select SU;
scrapInChargeBindingSource.DataSource = query;
I need to add a column that shows the percentage of the total HeatNumber weight that each ChargeNumber makes up. I did figure how to get the total weight of each heat by HeatNumber.
var TotalHeatWgt = from a in dct.ScrapInCharges
where ((a.DOB >= dateTimePicker2.Value.Date) &&
(a.DOB <= dateTimePicker1.Value.Date))
group a.Weight by a.HeatNumber
into b
select new { HeatNumber = b.Key, TotalWgt = b.Sum() };
I am currently stuck on how to combine this into a single C# query inserting a % of Heat column after the weight column. Can this be done or would I need to add an unbound column to the dataGridView % of Heat and iterate over the rows using my return values of the TotalHeatWgt query?