select * from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','238-003','251-012','251-037','243-028','231-364','240-029')
查询出来的产品记录是按照索引顺序排列的,可是我想产品的顺序按照后面的括号里的sku顺序显示,不知道大家有什么方法吗?

解决方案 »

  1.   

    order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
      

  2.   

    没有简便的方法吧,只能写个split的存储过程,
    循环拼sql语句,
    拼成如下格式:
    select * from product where sku='119-041'
    union all
    select * from product where sku='120-051'
    ....
    最后
    exec ('....')
      

  3.   

    select * from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','238-003','251-012','251-037','243-028','231-364','240-029')
    order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')这样
      

  4.   

    order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
    这个里面的product是什么意思啊?
      

  5.   


    select *,
        dispseq = charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
    from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','238-003','251-012','251-037','243-028','231-364','240-029')
    order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
    这样就明白了。1楼的想法真棒!
      

  6.   

    --应该是
    order by charindex(','+ltrim(sku)+',',',119-041,120-051,114-017,101-085....,')