Get the minimum value between several columns

后端 未结 4 573
遇见更好的自我
遇见更好的自我 2020-12-20 19:35

I\'m using SQL Server 2008;

Suppose I have a table \'X\' with columns \'Date1\', \'Date2\', \'Dateblah\', all of type DateTime.

I want to select the min valu

4条回答
  •  长情又很酷
    2020-12-20 19:48

    based on scalar function (from Tom Hunter):

    SELECT ID, (SELECT MIN([date]) FROM (VALUES(Date1),(Date2),(Dateblah)) x([date])) MinDate
    FROM TableName
    

提交回复
热议问题