Order by with CASE, not always what you expect

Oopps! Upgrade your browser pretty please.Oopps! Upgrade your browser pretty please.

I checked BOL the other day for ORDER BY integer. I found:

order_by_expression Specifies a column on which to sort. A sort column can be specified as a name or column alias, or a nonnegative integer representing the position of the name or alias in the select list.

So I gave it a try and created this table: CREATE TABLE dbo.Φ( ß int NOT NULL, Σ int NOT NULL ) GO INSERT INTO dbo.Φ (ß,Σ)VALUES (2,9) INSERT INTO dbo.Φ (ß,Σ)VALUES (7,5) INSERT INTO dbo.Φ (ß,Σ)VALUES (1,9) GO Then I tried this select: SELECT ß,Σ FROM dbo.Φ ORDER BY 2 and it gave me as expected: ß Σ 7 5 1 9 2 9 Then I tried this select: DECLARE @OrderBy char(1) SET @OrderBy = 'ß' SELECT ß,Σ FROM dbo.Φ ORDER BY CASE WHEN @OrderBy = 'ß' THEN 1 END ASC, CASE WHEN @OrderBy = 'Σ' THEN 2 END ASC, CASE WHEN @OrderBy NOT IN ('ß','Σ') THEN 2 END ASC and it gave me NOT as expected: ß Σ 2 9 7 5 1 9