举例:

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

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,%'
sql server如何精准匹配字符中的字符,绝对匹配

 

解决(2):

利用如mysql中的find_in_set办法

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

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

 

相关文章:

  • 2022-01-05
  • 2021-05-29
  • 2021-11-15
  • 2022-01-04
猜你喜欢
  • 2021-11-06
  • 2021-12-31
  • 2021-11-06
  • 2021-12-08
  • 2022-01-21
  • 2021-11-26
相关资源
相似解决方案