Did you ever think that it would be great to cache SQL Server database query…
I checked BOL the other day for ORDER BY integer. I found:
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