关于判断字段值是否包含某个值的问题

ahking 2008-07-24 09:54:02
字段值的格式为
**;***;***;*****

字符串由分号分隔,字符串长度和分号个数不定;分号有可能一个没有

要求找出分号隔开的字符串完全匹配某一给定值的记录

不知说清楚了么
...全文
130 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzy_love_sly 2008-07-24
  • 打赏
  • 举报
回复
create table tb(s varchar(50))
insert into tb select '1'
insert into tb select '1;2'
insert into tb select '1;2;3'
insert into tb select '2'

declare @s varchar(50)
set @s='1'

if exists(select 1 from tb where charindex(';'+@s+';',';'+s+';')>0)
print 'yes'
else
print 'no'


yes
青锋-SS 2008-07-24
  • 打赏
  • 举报
回复
select * from tb where charindex(';'+your_value+';',';'+column+';')>0
wzy_love_sly 2008-07-24
  • 打赏
  • 举报
回复
用charindex

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧