请教:int类型的字段如何实现A是B的子串?(在SQL语句中)

比如:
A='101';B='100,101,102,103'
select * from tablename where [a是b的子串]

但现在A是1个int类型,如何实现? 请赐教...
---------------------------------------------------------------

用cast(A as varchar(3))把A转化为字符串类型
---------------------------------------------------------------

搞错了:
select * from tablename where charindex(cast(A as char(3)),B)>0

---------------------------------------------------------------

select * from tablename where charindex(','+(cast a as varchar)+',',','+b+',')>0
---------------------------------------------------------------

select * from tablename where CHARINDEX(A, B, 1) > 0
---------------------------------------------------------------

select * from tablename where CHARINDEX(cast(A as varchar(3)), B, 1) > 0

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus