environment: microsoft sql server 2005, 2008
given:
IF object_id('tempdb..#MyTempTable') IS NOT NULL
BEGIN
DROP TABLE #MyTempTable
END
CREATE TABLE #MyTempTable
(
ID int IDENTITY(1,1)
, date1 datetime
, date2 datetime
, date3 datetime
)
INSERT INTO #MyTempTable
SELECT '3/1/2012','3/2/2012',NULL
table datetest
id,date1,date2,date3
------------------------
1, 3/1/2012,3/2/2012,null
2, 3/1/2012,null,null
all 3 dates can be null and up to 3 dates can be entered.
how do you get the most recent date?
for example, if date1 and date2 were filled out for a row, how would you get the most recent date of the 2 columns for that row?