Coalesce seems to work with any number of parameters and return the first one that is not null. How can I write a function like that? One that does not have a fixed number of parameters?
An example of the usage of a function fMax:
select Length = dbo.fMax(box.Height, box.Width, box.Depth)
from dbo.tBox box
where box.ShipmentId = 1234
With such a function I would not have to write something like this:
select Length = (
select MAX(side)
from (values (box.Height), (box.Width), (box.Depth)) as sides(side))
from dbo.tBox box
where box.ShipmentId = 1234