Finding the highest value in several SQL Server columns
You have a SQL Server table with n columns containing integers, floats, money, or dates, and it’s your task to return the maximum value contained on a row from these columns. You may even be required to do this for multiple rows at once, returning a record set.The first supposition suggests that you may not know in advance which or how many columns to compare, but this may not always be true. It’s possible that you always know exactly which columns to compare and know that it’s unlikely that any new ones will be added. On the other hand, you may have to program defensively, anticipating that some new column(s) might be added. Writing a function that compares exactly n values would do the job, but how useful would that be elsewhere?