日期:2014-05-19  浏览次数:20463 次

int和varchar转换比较的问题
有两个段:student_id是int类型,service_student是varchar类型,现在想做的是比较student_id与service_student的值,如果student_id在service_student中,则输出对应的student_id。
问题:怎样写语句来确认student_id的值在service_student中有相应值对应?
如:student_id= '109 '   service_student= '107,109,108 '
新手上路,请大虾们不吝赐教!

------解决方案--------------------
select
*
from

where
charindex( ', '+rtrim(student_id)+ ', ' , ', '+service_student+ ', ' ) > 0
------解决方案--------------------
select * from 表
where charindex( ', '+convert(varchar,student_id)+ ', ' , ', '+service_student+ ', ' ) > 0