I have 2 tables with the following fields:
Person
ID, LastName, FirstName
Assignment
PersonID, AssignmentDate, OtherField
Let's say the table data looks like this:
Person
- 1, Smith, John
- 2, Allen, James
- 3, Stone, Emma
Assignment
1, 12/1/2016, Blue
1, 1/1/2017, Green
1, 1/1/2018, Red
2, 5/5/2015, Yellow
I'm building a report, and the logic states that...
- if the AssignmentDate's YEAR ends in an EVEN number, report the even number (if year is 2014, report 2014).
- If the AssignmentDate's year ends in an ODD number, report the year minus 1 (i.e., year is 2015, report 2014).
In addition, group by PersonID followed by that "even" AssignedYear. Include all persons and all assignments. (I wasn't sure if I should be using Group By or Distinct. Confused on this part.)
I need it to output these results based off the example table:
1, 2016
1, 2018
2, 2014
3, null (since personID = 3 exists, but there are no assignments, we still want to incorporate this person)
How would you do that? I've gotten this far, but got stuck. :(
var t = from p in tblPersons
join a in tblAssignments
on p.ID equals a.PersonID into fml
from x in fml
select new AssignmentFilters
{
PersonID = x.PersonID,
Person= x.tblPersons.LastName + ", " + x.tblPersons.FirstName +
(string.IsNullOrEmpty(x.tblPersons.PreferredName) ? "" : " (" + x.tblPersons.PreferredName + ")") +
(string.IsNullOrEmpty(x.tblPersons.MiddleName) ? "" : " " + x.tblPersons.MiddleName) +
(string.IsNullOrEmpty(x.tblPersons.Suffix) ? "" : " " + x.tblPersons.Suffix),
AuditStartYear = x.DateAssigned == null ? 0 : (x.DateAssigned.Year % 2 == 0 ? x.DateAssigned.Year : x.DateAssigned.Year - 1)
};
Any help would be greatly appreciated! Been working on this for the past few hours and am just frustrated/stumped, lol. Thank you!