日期:2014-05-18  浏览次数:20369 次

问一个存储过程中关于in的排序问题
比如:
set @str='2,1,3,5,4' 
select t from R_info where id in (@str) 

得出的结果排序是按1,2,3,4,5排的。。

我现在要的是怎么让他按@str的顺序排。请高手帮帮忙。。。

------解决方案--------------------
SQL code
select t from R_info where charindex(','+ltrim(id)+',',','+@str+',')>0

------解决方案--------------------
SQL code
select t from R_info where charindex(','+ltrim(id)+',',','+@str+',')>0 order by charindex(','+ltrim(id)+',',','+@str+',')