I have never seen this type of SQL join statement before. It seems very complicated, and I'm very confused by how it works. Can someone explain it?
CASE WHEN @groupBy = 1 THEN 'Salesperson: '
WHEN @groupBy = 2 THEN 'Third Party Salesperson: '
END + ISNULL(gb.Name1 + ' (' + gb.Code + ')', '(none)') as GroupByName,
from @loanInfoTotals t
left join Entity gb on (@groupBy = 0 and 1 = 2)
or (@groupBy = 1 and gb.PartyId = t.SalespersonId)
or (@groupBy = 2 and gb.PartyId = t.ThirdPartySalespersonId)