I use SQL Server 2008 R2.
SQL Server 2008 R2
I need to sort a table by the minimal value of two columns.
The table looks like this:
ID: integer; Date
SELECT ID, Date1, Date2 FROM YourTable ORDER BY (SELECT TOP(1) v FROM (VALUES (Date1), (Date2)) AS value(v) ORDER BY v)
Very similar to the @dyatchenko answer but without NULL issue