sql判断字符是否在字符串中,字符串用,隔开

2025-02-26 14:31:51
推荐回答(3个)
回答1:

select * from tablename where 字段名 in ('aa')
这个就是用到了in关键字,同样的还有not in关键字查询的便是不包含某字符串的结果。
如果需要判断是否在,如果在(或者不在)需要返回值的话,用is null关键字加一个判断,判断一下就可以了。

回答2:

if exists(select 1 from table where aa='aa' ) or
exists(select 1 from table where bb='aa' ) or
exists(select 1 from table where cc='aa' )
print 'exists aa'
else
print 'Not exists aa'

判断是否有逗号用charindex()
逐条记录处理可以用游标
具体自己去 baidu & google,你很懒很固执

select * from table where left(MName,charindex(',',MName)-1) ='aa' and left(ISDel,charindex(',',ISDel)-1) ='1'

回答3:

aa,bb,cc,ss是记录还是字段名?