Fai*_*aiz 3 t-sql sql-server stored-procedures
我试图在存储过程中按子句顺序放置变量,但它返回一个错误。代码如下;
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)
对于一小组候选订单;
ORDER BY
CASE @ORDER WHEN 1 THEN fld1 END,
CASE @ORDER WHEN 2 THEN fld2 END,
CASE @ORDER WHEN 3 THEN fld3 END
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6420 次 |
| 最近记录: |