Why do ASC and DESC come *after* a CASE clause? This query works:

DECLARE @Ordering NVARCHAR(50)
SET @Ordering = 'aggregateid'

DECLARE @OrderDirectionInt INT
SET @OrderDirectionInt = 0 --1

SELECT * FROM (
    SELECT
        ROW_NUMBER() OVER (ORDER BY
            CASE WHEN LOWER(@Ordering) = 'aggregateid' AND @OrderDirectionInt = 1 THEN AggregateId END DESC,
            CASE WHEN LOWER(@Ordering) = 'aggregateid' AND @OrderDirectionInt = 0 THEN AggregateId END ASC
        ) AS RowNumber,
        MyField
    FROM
        MyTable
) AS TempResults
WHERE TempResults.RowNumber BETWEEN 12 AND 23


What I don't understand is why the ASC and DESC are after (or outside of) the CASE statements.  It looks like the ASC and DESC are being put in unconditionally, which doesn't make sense... it might resolve to:

ROW_NUMBER() OVER (ORDER BY
    DESC,
    AggregateId ASC
) AS RowNumber


Why doesn't the CASE statement contain the ASC or DESC (if you try to do that you get a syntax error)?
Why do ASC and DESC come after a CASE clause?  
Why doesn't the CASE statement contain the ASC or DESC (if you try to do that you get a syntax error)?


Because a CASE expression (it's neither a clause nor a statement) can have a value/expression as a result, not code words like ASC or FROM. The syntax provided in CASE expression documentation is:

Searched CASE expression:
CASE
     WHEN Boolean_expression 
       THEN result_expression [ ...n ] 
     [ ELSE else_result_expression ] 
END



It might resolve to:

ROW_NUMBER() OVER (ORDER BY
    DESC,
    AggregateId ASC
) AS RowNumber



No, it cannot. Due to the implied ELSE NULL part that all CASE expressions have as a default, if you don't provide it.