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)就不能查询到结果 求助 谢谢了
select count(1) from xj_teachresinfo
where ti_shenhe=1 and ti_ui_id=1 and ti_leixing in (713,714)
将 varchar 值 '713,714' 转换为数据类型为 int 的列时发生语法错误。
select count(1) from xj_teachresinfo where ti_shenhe=1 and ti_ui_id=1
and charindex(ltrim(ti_leixing),'713,714')>0
CHARINDEX的用法:
;with t as(
select '1,2,3,4,5,6' f
)
select CHARINDEX('3,4',f)
from t你的程序逻辑有问题!