当前位置: 代码迷 >> Sql Server >> 字段中有数组如何查询
  详细解决方案

字段中有数组如何查询

热度:107   发布时间:2016-04-27 21:12:42.0
字段中有数组怎么查询?
有很多记录每个记录里有个字段(存放的是数组的值[如:1,2,3,4,5,6])   目前要查出数组值里必须都大于3的所有记录(比如:5,5,5,5,5,5   或   5,6,4,6,5,6)
请问怎么写WHERE???

------解决方案--------------------
declare @a table(a varchar(100))
insert @a select '1,2,3,4,5,6 '
union all select '5,5,5,5,5,5 '
union all select '5,6,4,6,5,6 '

select * from @a where patindex( '%[0-3]% ',a)=0

------解决方案--------------------
select * from @a where patindex( '%,[0-3],% ', ', '+a+ ', ')=0
union
select * from @a where patindex( '[0-3],% ',a+ ', ')=0
union
select * from @a where patindex( '%,[0-3] ', ', '+a)=0

试试
  相关解决方案