我在asp.net中用到一句“select * from 表 where in 字符串”,字符串内容是用逗号隔开的记录ID,得到的结果是按ID号从小到大进行了排序,我现在想要的是不进行排序,而是按照字符串是的ID顺序,请问应该用什么 样的语句呢?

解决方案 »

  1.   

    方法有很多。可以从新组装 查询出来的结果 DataTable
      

  2.   

    我很菜,请具体说明一下?我是在asp.net中用的这个语句。谢谢!
      

  3.   


    create table t0444(id int,col varchar(1))
    insert into t0444
    select 1,'a' union all
    select 2,'b' union all
    select 3,'c' union all
    select 4,'d' union all
    select 5,'e' union all
    select 6,'f' union all
    select 7,'g' union all
    select 8,'h' union all
    select 9,'i'declare @t varchar(20)
    set @t='4,1,6,3'
    exec('select * from t0444 where id in ('+@t+')')
    /*
    id          col
    ----------- ----
    1           a
    3           c
    4           d
    6           f
    */select * from t0444 where id in (4,1,6,3) 
    order by charindex(','+cast(id as varchar(20))+',',','+'4,1,6,3'+',')
    /*
    id          col
    ----------- ----
    4           d
    1           a
    6           f
    3           c
    */