Selecting most recent date between two columns

前端 未结 13 1370
再見小時候
再見小時候 2020-12-30 22:15

If I have a table that (among other columns) has two DATETIME columns, how would I select the most recent date from those two columns.

Example:

13条回答
  •  天涯浪人
    2020-12-30 23:07

    From SQL Server 2012 it's possible to use the shortcut IIF to CASE expression though the latter is SQL Standard:

    SELECT ID,
           IIF(DateColA > DateColB, DateColA, DateColB) AS MostRecentDate
      FROM theTable
    

提交回复
热议问题