我正在比較兩個日期並試圖確定兩個日期的最大值。空日期將被視爲低於有效日期。我正在使用下面的案例陳述,它適用於 - 但感覺非常低效和笨重。有沒有更好的辦法?T-SQL確定日期最大值的更好方法(佔空位)
update @TEMP_EARNED
set nextearn = case when lastoccurrence is null and lastearned is null then null
when lastoccurrence is null then lastearned
when lastearned is null then lastoccurrence
when lastoccurrence > lastearned then lastoccurrence
else lastearned end;
(這是在MS SQL 2000,僅供參考。)
對於datetime的SQL Server字段,可以存儲的最早日期爲1753年1月1日,http://msdn.microsoft.com/zh-cn/library/ms187819.aspx。Smalldatetime的最小值是1900年1月1日。因此,文本字符串中使用的最小值取決於類型。 – 2010-05-20 16:35:19
我不知道,答案更新。 – 2010-05-20 16:45:01