Coalesce 似乎可以使用任意数量的参数并返回第一个不为空的参数。我怎样才能写出这样的函数呢?没有固定数量的参数?
函数 fMax 的使用示例:
select Length = dbo.fMax(box.Height, box.Width, box.Depth)
from dbo.tBox box
where box.ShipmentId = 1234
有了这样的函数,我就不必写这样的东西了:
select Length = (
select MAX(side)
from (values (box.Height), (box.Width), (box.Depth)) as sides(side))
from dbo.tBox box
where box.ShipmentId = 1234
最佳答案
如果您使用 SQL Server 2008 及更高版本,则可以使用 Table-Valued Parameters .
关于sql-server - 如何在 SQL Server 中编写任意数量的参数函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18978844/