Possible Duplicate:
Getting the minimum of two values in sql
Okay what I Have a table with two datetime fields and I want to select the rows where the oldest date is equal to some date variable. I saw the LEAST function used somewhere but I can’t use this in T-SQL
I need something like this
SELECT LEAST(date1, date2) as theDate FROM theTable WHERE theDate = '2012-09-24'
but that will work in T-SQL. Also date1 or date2 can sometimes be null so that may be important to know.
There is no such function in T-SQL. Try:
To handle NULLs you may want:
Also, you can’t reference the alias
theDatein theWHEREclause, it doesn’t exist yet. You might want to say: