Procedure @P1 int as
Select a, b, c from table1
order by ????
当P1=1 时按a排序,
当P1=2 时按b排序,
当P1=3 时按c排序。
怎么写? 谢谢
------解决方案--------------------
Procedure @P1 int as
Select a, b, c from table1
order by case @P1 when 1 then a when 2 then b when 3 then c
------解决方案--------------------
- SQL code
gocreate proc pro_tracy@P1 intasif @P1=1beginSelect a, b, c from table1 order by aendif @P1=2beginSelect a, b, c from table1 order by bendif @P1=3beginSelect a, b, c from table1 order by cend
------解决方案--------------------
还可以使用order by case when @P1=1 then a when @P1=2 then b when @P1=3 then c end