GREATEST and LEAST functions!
So, this is pretty cool. Microsoft have brought GREATEST
and LEAST
functions to SQL Azure, and will be bringing them to on premise versions in a later release (presumably that means the next release).
These work like scalar functions versions of the MIN
and MAX
aggregations, you write something like GREATEST(1, 3, 4, 2, 6, 7, 5, 9, 13)
and it returns the maximum of the values entered (13 in this case). The article gives a few use cases, and there is full documentation for both GREATEST and LEAST in Microsoft Docs.
This is something that’s been wanted for a long time, and in its absence we’ve often resorted to some complicated CASE
statements that we’d probably all like to forget, so I’m really happy it’s there in Azure and coming soon to on prem. Now I just have to convince my company that we should probably migrate of SQL 2008 at some point…