select count(1) from xj_teachresinfo where  ti_shenhe=1 and ti_ui_id=1  and  charindex('713,714', ti_leixing)>0其中ti_leixing为int值上述SQL语句中的  charindex('713,714', ti_leixing)   始终查询为0如果改为charindex('714', ti_leixing) 查询正确    一旦有多个字符 形如: charindex('714,715,716', ti_leixing)就不能查询到结果   求助   谢谢了

解决方案 »

  1.   


    select count(1) from xj_teachresinfo 
    where  ti_shenhe=1 and ti_ui_id=1  and ti_leixing in (713,714)
      

  2.   

    如果按照你上面写的   .NET系统运行时报错  如下:
    将 varchar 值 '713,714' 转换为数据类型为 int 的列时发生语法错误。 
      

  3.   


    select count(1) from xj_teachresinfo where  ti_shenhe=1 and ti_ui_id=1  
    and  charindex(ltrim(ti_leixing),'713,714')>0
      

  4.   


    CHARINDEX的用法:
    ;with t as(
    select '1,2,3,4,5,6' f
    )
    select CHARINDEX('3,4',f)
    from t你的程序逻辑有问题!
      

  5.   

    select count(1) from xj_teachresinfo where  ti_shenhe=1 and ti_ui_id=1  and  charindex(','+rtrim(ti_leixing)+',', ','+'713,714'+',')>0 --应该查询字段及查询目标字符串前后都加上单引号