日期:2014-05-16  浏览次数:20720 次

高手请进!字符串查询问题
问题如下:
access库,字段unit中存储数据如下:
id                 unit
1               6,8,12,14
2               8,9,10
3               7,15,18,19,28
4               6,22,18,14,17
......
查询变量a在unit字段中的所有的记录(比如a=8,查询unit字段所有包含8的记录。即id是1和2的记录)。查询语句怎么写?急!!!!多谢!

------解决方案--------------------
正确解法:

select * from yourTable
where unit like '8,% '
or unit like '%,8,% '
or unit like '%,8 '
or unit = '8 '
------解决方案--------------------
--如果是纯Access环境

select *
from 表名
where ', ' & unit & ', ' like '*,8,* '


--如果是ADO的SQL串

select *
from 表名
where ', ' & unit & ', ' like '%,8,% '