Unanswered: How do I make a date sort-order dependent on a variable?
In a TSQL Stored Proc I want to make the sort-order of a date field dependent on a variable. This is easy to if it's an integer field (a case statement with negative result to get the descending version), but I can't think how to do it for a date. For example, this is what I'd like to do:-
declare @SortOrder int
set @SortOrder = 0
select dateadd(dd,1,getdate()) myDateField
then myDateField -- Ascending
else -1*myDateField -- Descending
Unfortunately "*-1*myDateField" is not legal. Any suggestions?
I'd really like this to be in one statement.