sql server如何精准匹配字符中的字符,绝对匹配

举例:

    

我现在是需要查询这字段里包含1的数据 

 我如果直接charindex,那么11,12也会被包含。

解决(1):

select * 
from
(
    select '1,2,12,111' as  str
    union all 
    select '2,12,111'
    union all
    select '1'
) t1
where  ','+str+',' like'%,1,%'

解决(2):

利用如mysql中的find_in_set办法

自己写一个自定义函数split,利用outer apply,这个比较简单,这里不做赘述。

split 函数 可以参考:https://www.cnblogs.com/gered/p/9887536.html

原文地址:https://www.cnblogs.com/gered/p/11394746.html