select * from [test] where id in (3,2,4,5,8,6) order by charindex(cast(id as varchar),'3,2,4,5,8,6')
这是对select where in类的排序
还有select in的总结
如果用存储过程实现select in
如id为int型 f_id为varchar 假如f_id为1,2,5,6
select * from [test] where id in (f_id)在存储过程中给id和f_id传入参数的话 像下面的存储过程就会出错
create Procedure [dbo].[getInfo]
(
@id int,@f_id varchar
)
as select * from [test] where @id in (@f_id)就会出错
改为:
decalre @str
set @str='select * from [test] where '+@id in +'('+@f_id+')'
exec (@str)就ok了