Finding the highest value in several SQL Server columns

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?

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 14 + 9 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)