在 MS SQL Server 2005 中,我正在编写一个带有条件排序的查询,我的问题是我不知道如何使用两列进行条件排序?
如果我写了这样的代码,它就可以正常工作
select
*
from
table
order by
case @pkr
when 'kol' then kol
when 'nci' then nci
end
Run Code Online (Sandbox Code Playgroud)
我不知道如何对两列或更多列进行条件排序
select
*
from
table
order by
case @pkr
when 'KOL-NCI' then kol,nci
when 'kol-MPCI' then kol,mpci
end
Run Code Online (Sandbox Code Playgroud)
有一个制作动态 TSQL 并使用的想法,sp_executesql
但我仍在寻找更好的想法?