Excel的“T”SQL等价物“MAX”功能返回两个数字较大 [英] T-SQL equivalent of Excel "MAX" function to return larger of two numbers
问题描述
Possible Duplicate:
Is there a Max function in SQL Server that takes two values like Math.Max in .NET?
在Excel中,有一个名为MAX的函数接受数字并返回最大的一个在集合。 T-SQL中是否存在复制此功能的功能?我没有找到一个,我已经写了一个UDF,为我做,但我认为这是值得问的。
In Excel, there's a function called "MAX" that accepts numbers and returns the largest one in the set. Is there a function in T-SQL that duplicates this functionality? I haven't been able to find one, and I've written a UDF that does it for me, but I thought it was worth asking.
这是功能我一直在使用:
Here is the function I've been using:
CREATE FUNCTION dbo.LargerOf
(
-- Add the parameters for the function here
@First FLOAT,
@Second FLOAT
)
RETURNS FLOAT
AS
BEGIN
DECLARE @Result FLOAT
IF @First > @Second
SET @result = @First
ELSE
SET @Result = @Second
RETURN @Result
END
GO
我不期望有任何运气,而不是将我的功能移动到一大堆新的服务器,我以为我至少要问。谢谢!
I don't expect any luck, but instead of moving my function to a whole bunch of new servers, I thought I'd at least ask. Thanks!
推荐答案
我不知道你需要的功能是否存在,但为了解决方法,我更喜欢这个/ p>
I don't know if the function you need exists, but for a workaround, I like this one better
set @max = case when @first > @second then @first else @second end
这篇关于Excel的“T”SQL等价物“MAX”功能返回两个数字较大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!