Last active
December 30, 2015 10:28
-
-
Save craibuc/7815672 to your computer and use it in GitHub Desktop.
A SQL Server, scalar-value function that returns the lesser of two dates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set ANSI_NULLS ON | |
| set QUOTED_IDENTIFIER ON | |
| GO | |
| /*---------------------------------------------------------------------------------------------------- | |
| Author: Craig Buchanan | |
| Date: 2/6/2006 | |
| Description: Returns the lesser of two dates | |
| Parameters: | |
| @Date1 - datetime to be compared | |
| @Date2 - datetime to be compared | |
| ----------------------------------------------------------------------------------------------------*/ | |
| CREATE FUNCTION [dbo].[MinimumDate] ( | |
| @Date1 datetime, | |
| @Date2 datetime | |
| ) | |
| RETURNS datetime AS | |
| BEGIN | |
| RETURN CASE | |
| WHEN @Date1 IS NULL AND @Date2 IS NULL THEN NULL | |
| WHEN @Date1 IS NULL THEN @Date2 | |
| WHEN @Date2 IS NULL THEN @Date1 | |
| WHEN @Date1 < @Date2 THEN @Date1 | |
| WHEN @Date2 < @Date1 THEN @Date2 | |
| WHEN @Date2 = @Date1 THEN @Date2 | |
| ELSE NULL | |
| END | |
| END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment