我试图在存储过程中按子句顺序放置变量,但它返回一个错误。代码如下;
SELECT ...
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.SQL_HANDLE) AS st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
WHERE @where LIKE '%'+@search+'%'
ORDER BY CASE @ORDER
Run Code Online (Sandbox Code Playgroud)
错误是;
'Msg 1008, Level 16, State 1, Procedure sp_ExecInfo2, Line 40
The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.'
Run Code Online (Sandbox Code Playgroud)