I have the following query and can't get it to work when I replace the order by [Mach No] with parameters to make it a dynamic clause. I have read several posts about using Case and when and replacing the calculated name with the actual calculation but I feel that the problem relies on the table aliases which are necessary to get the calculations to work. It is a self joined table.I have the following query and can't get it to