Rx_
Nothing In Moderation
- Local time
- Today, 11:17
- Joined
- Oct 22, 2009
- Messages
- 2,803
There are 5 Variables with any combination of Null or a valid date.
The objective is to identify the variable with the latest (most recent) date.
Note: I don't want the actual date returned
Instead, I want to know what variable the latest date was in.
If @StAPDApprovedDt and @StAPDExpired were the only two with dates, and
@StAPDExpired was the most recent date then return the string 'StAPDExpired'
Code properly assigns these 5 variables with either Null or a valid date
--DECLARE @StAPDApprovedDt as DATETIME
--DECLARE @StAPDExpired as DATETIME
--DECLARE @StAPDWithDrawn as DATETIME
--DECLARE @StAPDDenied as DATETIME
--DECLARE @StAPDReturned as DATETIME
If all of them are null, return an empty string e.g.
IF (NULLIF(@StAPDApprovedDt, '') Is Null AND NULLIF(StAPDExpired, '')
Is Null AND NULLIF(StAPDWithDrawn, '') Is Null AND NULLIF(StAPDDenied, '')
Is Null AND NULLIF(StAPDReturned, '') Is Null)
Set @CharResult = ''; --All dates are Null, return empty string
The objective is to identify the variable with the latest (most recent) date.
Note: I don't want the actual date returned
Instead, I want to know what variable the latest date was in.
If @StAPDApprovedDt and @StAPDExpired were the only two with dates, and
@StAPDExpired was the most recent date then return the string 'StAPDExpired'
Code properly assigns these 5 variables with either Null or a valid date
--DECLARE @StAPDApprovedDt as DATETIME
--DECLARE @StAPDExpired as DATETIME
--DECLARE @StAPDWithDrawn as DATETIME
--DECLARE @StAPDDenied as DATETIME
--DECLARE @StAPDReturned as DATETIME
If all of them are null, return an empty string e.g.
IF (NULLIF(@StAPDApprovedDt, '') Is Null AND NULLIF(StAPDExpired, '')
Is Null AND NULLIF(StAPDWithDrawn, '') Is Null AND NULLIF(StAPDDenied, '')
Is Null AND NULLIF(StAPDReturned, '') Is Null)
Set @CharResult = ''; --All dates are Null, return empty string