我有这个表用户我需要按参数对选择结果进行排序,但是当我对像 userName 字段这样的 varchar 字段进行排序时遇到问题。如何解决?
----------------------------------------
| userID | UserName | password |...... |
----------------------------------------
| int | varchar | varcahr | ..... |
declare @index varchar(100)
set @index = 2
select * From users
order by case @index
when 1 then Number
when 2 then CAST(LoginName AS INT)
Else Password
End