Without dynamic SQL I want to achieve the following goal:
DECLARE @SortDesc bit = 1; SELECT * FROM Sales.SalesOrderHeader ORDER BY SalesOrderID CASE WHEN @SortDesc = 1 THEN DESC ELSE ASC END; /* Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'CASE'. */
I know it can be done with dynamic SQL. I wonder if there is a static SQL solution. Thanks.
Kalman Toth Database & OLAP Architect
sqlusa.com
New Book / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012