--试试这个.declare @temp varchar(30)
select @temp='3,4,5'
select * from tbl_subjects where charindex(cast(subjectID as varchar(10)),@temp)>0

解决方案 »

  1.   

    --测试
    --创建表
    create table tbl_subjects(subjectID int)
    --插入数据
    insert tbl_subjects
    select 3
    union select 5
    union select 8
    union select 4
    --查询
    declare @temp varchar(30)
    select @temp='3,4,5'
    select * from tbl_subjects where charindex(cast(subjectID as varchar(10)),@temp)>0
    --结果
    /*
    subjectID   
    ----------- 
    4
    3
    5(所影响的行数为 3 行)
    */
      

  2.   

    --试试这个.declare @temp varchar(30)
    select @temp='3,4,5'
    select * from tbl_subjects 
    where charindex(','+
         cast(subjectID as varchar(10))'+','   ,   ','+@temp+',')>0
      

  3.   

    谢谢mschen(Visual【陈】) 及 lishengyu(玉)能不能详细地解释一下,然后我结帖!
      

  4.   

    TO:mschen(Visual【陈】) 你的方法可行,谢谢!!
      

  5.   

    to  mschen(Visual【陈】) 
    select @temp='3458' 时 
    你的结果有误
      

  6.   

    declare @temp varchar(30)
    select @temp='3,48,5'
    select * from tbl_subjects 
    where charindex(','+
         cast(subjectID as varchar(10))+','   ,   ','+@temp+',')>0
    这样就没错了
      

  7.   

    declare @temp varchar(30)
    select @temp='3,4,5'
    exec(select * from tbl_subjects where subjectID in '+'('+''''@temp+''''+')')