Conditional ORDER BY depending on column values
问题 I need to write a query that does this: SELECT TOP 1 FROM a list of tables (Joins, etc) ORDER BY Column X, Column Y, Column Z If ColumnX is NOT NULL , then at the moment, I reselect, using a slightly different ORDER BY . So, I do the same query, twice. If the first one has a NULL in a certain column, I return that row from my procedure. However, if the value isn't NULL - I have to do another identical select, except, order by a different column or two. What I do now is select it into a temp