一个订单表table_a 其中有个字段记录订单类别(一个数字表类别)
由管理员管理类别的字符串,如何查出所管理的类别。比如 管理员管理的类别是字段存的字符串是 1,3,7如何快速查出table_a中订单是1 3 7的订单呢?

解决方案 »

  1.   


    select *
    from table_a
    where 订单类别 in (1,3,7)--orselect *
    from table_a
    where charindex(','+ltrim(订单类别)+',',','+'1,3,7'+',') > 0
      

  2.   

    declare @id varchar(20)
    set @id='1,3,7'
    select * from table_a where charindex(','+ltrim(订单类别)+',',','+ @id+',')>0
      

  3.   

    select
     *
    from
     tb
    where
     charindex(','+ltrim(订单类别)+',',','+'1,3,7'+',') > 0
      

  4.   

    select * from tb where charindex(','+ltrim(订单类别)+',',','+ @id+',')>0
      

  5.   

    select * from table_a 
    where 订单类别 in (1,3,7)
      

  6.   

    select
     *
    from
     tb
    where
     charindex(','+ltrim(订单类别)+',',','+'1,3,7'+',') > 0
      

  7.   

    select
     *
    from
     tb
    where
     charindex(','+ltrim(订单类别)+',',','+'1,3,7'+',') > 0