avatech
asked on
Oldest date of 4 assigned to variables
Happy Monday! I am new to SQL coding and I want to look for a condition where the oldest date value is determined and then assigned to a new variable. Example:
Which of these four is the oldest (by date) and return it as a new variable @Oldest. These four variables will never have the same value.
@var1 = 01-20-14 12:51:00.000
@var2 = 01-20-14 12:52:00.000
@var3 = 01-20-14 12:53:00.000
@var4 = 01-20-14 12:54:00.000
@Oldest = ????
How would I structure this in SQL?
Which of these four is the oldest (by date) and return it as a new variable @Oldest. These four variables will never have the same value.
@var1 = 01-20-14 12:51:00.000
@var2 = 01-20-14 12:52:00.000
@var3 = 01-20-14 12:53:00.000
@var4 = 01-20-14 12:54:00.000
@Oldest = ????
How would I structure this in SQL?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick responses! I need to keep it as simple as possible. I am setting up a condition for NAGIOS to show me the oldest of the four dates. So far the Old Fashioned seems most appropriate but I do like the first.
ASKER
I liked all of the options and appreciate the rapid response. The best fit for me that I was able to test was the "Old Fashioned" although I liked the temp table using MIN. The third option seemed very efficient as well -- thank you all for contributing!
ASKER