请问如何按照in()中的id顺序排序?
现在有一个SQL语句
select * from tblexam where examid in (267245,262153,262503,261727,268787,230830,231627,260328,260691,261152,261717,261720,262093,262510,266181,267842,267873,304439,287744,236368,307139,307489,307541,307813,307834,312144,324878,260587,261149,322126)
examid是一个Int型的主键
现在如果按照这样的语句执行以后,取出来的结果并不是按照in()里面的examid顺序排列的。我想要一定按照in中的顺序排列,请问这个sql语句应该怎么写?
在此先多谢帮忙的各位了。
------解决方案--------------------select * from tblexam where examid in (267245,262153,262503,261727,268787,230830,231627,260328,260691,261152,261717,261720,262093,262510,266181,267842,267873,304439,287744,236368,307139,307489,307541,307813,307834,312144,324878,260587,261149,322126)
order by
charindex(rtrim(examid), '267245,262153,262503,261727,268787,230830,231627,260328,260691,261152,261717,261720,262093,262510,266181,267842,267873,304439,287744,236368,307139,307489,307541,307813,307834,312144,324878,260587,261149,322126 ')