0

I am working on a composite ranking website. I am trying to query the most recent ranking and the previous ranking side by side. This query works great in SSMS, but I am unable to make this work in my C# code:

SELECT r.Name, l.RankValue AS currentValue, l.RankDT as CurrentDT, p.RankValue AS prevVal, p.RankDT AS prevDate
FROM RankLookupTB L 
JOIN RankingsTB R ON L.RankID = R.RankID
FULL JOIN (SELECT rankid, rankvalue, RankDT FROM RankLookupTB WHERE Obselete = 1 and TeamID = 356) AS P ON l.RankID = p.RankID  
WHERE l.TeamID = 356 and Obselete = 0
ORDER BY r.Name

Here is what I have in my Program:

    var ranks = from r in _context.RankLookupTbs
                where r.TeamId == id && r.Obselete == false
                join s in _context.RankingsTbs on r.RankId equals s.RankId
                join t in _context.RankLookupTbs on new { id = r.RankId, obsolete = r.Obselete } equals new { id = t.RankId, obsolete = true }
                select new { Name = s.Name, CurrentValue = r.RankValue, CurrentDT = r.RankDt, PastValue = t.RankValue, PastDT = t.RankDt };

I am sure that I am not far away from the answer. The join seems to be the problem because I am getting everything in the result set.

Lastly, I downloaded LINQPad, but it is not giving me anything at all.

Thanks for all insights

snussel
  • 75
  • 5

0 Answers0