How can I add ELSE clause to the following code?
ROW_NUMBER() OVER (ORDER BY
CASE WHEN @OrderByColumn='ViewCount' AND @OrderDirection=0 THEN docsT.ViewCount END ASC,
CASE WHEN @OrderByColumn='AddedDate'AND @OrderDirection=0 THEN docsT.AddedDate END ASC,
CASE WHEN @OrderByColumn='AddedBy'AND @OrderDirection=0 THEN docsT.AddedBy END ASC,
CASE WHEN @OrderByColumn='Title' AND @OrderDirection=0 THEN docsT.Title END ASC
) AS RowNum
You can put the order in an outer case, and then for selecting the field you can use the form of the case where you compare one value to several values. To support ascending and descending sort, you have to repeat it all again.