where charindex(cast(id as varchar),@a) > 0

解决方案 »

  1.   


    where charindex(','+cast(id as varchar)+',',','+@a+',') > 0
      

  2.   

    declare @a varchar(20)
    set @a='1,2,3'
    --方法一:
    exec('select * from T where ID in (' + @a + ')')
    --方法二:
    select * from T where charindex(','+cast(ID as varchar)+',',',' + @a + ',') > 0
      

  3.   

    前台,如asp中,直接:sql="exec ('select * from T where ID in ('+'" & a & "'+')')"
    conn.execute(sql)