首页 > 代码库 > SQL 查询结果按参数顺序排列

SQL 查询结果按参数顺序排列

SELECT * FROM Project_Business_Type WHERE Id in (10,25,5,4,15,46,74,500)order by charindex(‘,‘+ltrim(Id)+‘,‘, ‘,10,25,5,4,15,46,74,500,‘)

  这里查询出来的结果就是按参数传进来的顺序,10,25,5,4...

 

order by charindex(‘,‘+ltrim(Id)+‘,‘, ‘,10,25,5,4,15,46,74,500,‘)  排列顺序

SQL 查询结果按参数顺序排列