SQL里好象默认都将SELECT出来的记录都做了排序的,现在有以下的语句:
SELECT * FROM tableName WHERE Class = '0' and Id in (252, 679, 321, 100, 270),我想在SELECT完以后,输出的结果是未排过序(那些id是怎么进来的就怎么排序):
252
679
321
100
270
SELECT * FROM tableName WHERE Class = '0' and Id in (252, 679, 321, 100, 270),我想在SELECT完以后,输出的结果是未排过序(那些id是怎么进来的就怎么排序):
252
679
321
100
270
我应该如何实现这样的效果呢?
方法一
SELECT * FROM tableName WHERE Class = '0' and Id in (252, 679, 321, 100, 270)order by charindex(','+ltrim(ClassID)+',', '," 252, 679, 321, 100, 270 ",')";
方法二
Select * FROM tableName Where ( Class = '0' and Id in ('252, 679, 321, 100, 270')) orDER BY PATINDEX('%,' + CONVERT(nvarchar(4000), ClassID) + ',%', ','+'252, 679, 321, 100, 270'+',')";