请教in的用法?

blueroute 2005-07-26 12:28:17
字段type是个字符串,如'2,3,4,5'

我用
select * from tablename where '2' in (type)
每次只能查处type只为'2'的记录,不能包含'2,3,4'的记录

请教!
...全文
88 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
joyco 2005-07-26
  • 打赏
  • 举报
回复
select * from tb1 where charindex(type,'2')=1
xueguang 2005-07-26
  • 打赏
  • 举报
回复
没必要用in,可以以下方法:
select * from tablename where type like '%2%'
select * from tablename where charindex('2',type)>0
子陌红尘 2005-07-26
  • 打赏
  • 举报
回复
select * from tablename where charindex(',2,',','+type+',')>0
vivianfdlpw 2005-07-26
  • 打赏
  • 举报
回复
select * from tablename where charindex(',2,',','+type+',')>0
liuzijing688 2005-07-26
  • 打赏
  • 举报
回复
select * from tablename where type like '%2%'
select * from tablename where charindex('2',type)>0
peanutsun 2005-07-26
  • 打赏
  • 举报
回复
select * from tablename where type in ('2','3','4','5')
GRLD8888 2005-07-26
  • 打赏
  • 举报
回复
select * from tb1 where charindex(name1,'2')=1

34,593

社区成员

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

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