MS SQL两个日期比较,获取最大或最小的日期
MS SQL两个日期比较,获取最大或最小的日期的函数。
如果你可以使用SQL 日期比较函数http://www.cnblogs.com/insus/archive/2011/06/24/2089005.html去实现。
获取最大的日期函数:
MaximumDate
CREATE FUNCTION [dbo].[MaximumDate] (
@DT1 DATETIME,
@DT2 DATETIME
)
RETURNS DATETIME
AS BEGIN
RETURN CASE
--有关DateTimeCompare可参考:http://www.cnblogs.com/insus/archive/2011/06/24/2089005.html
WHEN ([dbo].[DateTimeCompare](@DT1,@DT2) = 1) THEN @DT1 ELSE @DT2 END
END
@DT1 DATETIME,
@DT2 DATETIME
)
RETURNS DATETIME
AS BEGIN
RETURN CASE
--有关DateTimeCompare可参考:http://www.cnblogs.com/insus/archive/2011/06/24/2089005.html
WHEN ([dbo].[DateTimeCompare](@DT1,@DT2) = 1) THEN @DT1 ELSE @DT2 END
END
获取最小的日期函数:
MinimumDate
CREATE FUNCTION [dbo].[MinimumDate] (
@DT1 DATETIME,
@DT2 DATETIME
)
RETURNS DATETIME
AS BEGIN
RETURN CASE
--有关DateTimeCompare可参考:http://www.cnblogs.com/insus/archive/2011/06/24/2089005.html
WHEN ([dbo].[DateTimeCompare](@DT1,@DT2) = -1) THEN @DT1 ELSE @DT2 END
END
@DT1 DATETIME,
@DT2 DATETIME
)
RETURNS DATETIME
AS BEGIN
RETURN CASE
--有关DateTimeCompare可参考:http://www.cnblogs.com/insus/archive/2011/06/24/2089005.html
WHEN ([dbo].[DateTimeCompare](@DT1,@DT2) = -1) THEN @DT1 ELSE @DT2 END
END