ASP+access里charindex的用法

idhgd 2011-03-31 12:54:20
ID为aaa表的ID列,'1,2,3'为ID列里的编号的值,用逗号分隔。
我想通过以下语句查询编号分别为1,2,3的数据,不可以得到结果。请问,问题出在哪里,正确的该怎么写?
sql="select * from aaa where charindex('1,2,3',id)>0"
...全文
374 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwwb 2011-04-01
  • 打赏
  • 举报
回复
17楼的代码 是测试通过的
idhgd 2011-03-31
  • 打赏
  • 举报
回复
难道注定我要用循环……
idhgd 2011-03-31
  • 打赏
  • 举报
回复
ID是自动编号的字段
idhgd 2011-03-31
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 acmain_chm 的回复:]
<%
a="12,14,16"
set rs=conn.execute("select * from aaa where instr(',"&a&",',',"&id&",')>0")
%>
[/Quote]
这样是不行的,查询没有结果
ACMAIN_CHM 2011-03-31
  • 打赏
  • 举报
回复
<%
a="12,14,16"
set rs=conn.execute("select * from aaa where instr(',"&a&",',',"&id&",')>0")
%>
idhgd 2011-03-31
  • 打赏
  • 举报
回复
试了上面的不行。


<%
a="12,14,16"
set rs=conn.execute("select * from aaa where instr(',"&a&",',id)>0")
%>

这样出来的值是有id为1,2,4,6,12,14,16的值,如何改成只有12,14,16的值?
wwwwb 2011-03-31
  • 打赏
  • 举报
回复
Set rs = CurrentDb.OpenRecordset("select * from a where instr('," & aA & ",'" & ",','&" & "ID" & "&',')>0")
Do While Not rs.EOF
MsgBox rs(0)
rs.MoveNext
Loop
idhgd 2011-03-31
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 wwwwb 的回复:]
set rs=conn.execute("select * from aaa where instr('," & a & ",'" & ",'," & ID & ",')>0")
[/Quote]
这个不行,查不出来
wwwwb 2011-03-31
  • 打赏
  • 举报
回复
set rs=conn.execute("select * from aaa where instr('," & a & ",'" & ",'," & ID & ",')>0")
idhgd 2011-03-31
  • 打赏
  • 举报
回复
set rs=conn.execute("select * from aaa where instr(',' & a & ',',',' & id & ',')>0")

这样写不行
idhgd 2011-03-31
  • 打赏
  • 举报
回复
set rs=conn.execute("select * from aaa where instr(',' & '12,14,16' & ',',',' & id & ',')>0")

这一整句,里面的12,14,16换成变量a怎么写?
wwwwb 2011-03-31
  • 打赏
  • 举报
回复
SELECT instr(',' & a &',',',3,')
idhgd 2011-03-31
  • 打赏
  • 举报
回复
那12,14,16换成变量呢?a="12,14,16"
wwwwb 2011-03-31
  • 打赏
  • 举报
回复
select * from aaa where instr(','& '12,14,16' & ',',',' & id & ',')>0
idhgd 2011-03-31
  • 打赏
  • 举报
回复
set rs=conn.execute("select * from aaa where instr(',' & '12,14,16' & ',',',' & id & ',')>0")

这样就可以了
idhgd 2011-03-31
  • 打赏
  • 举报
回复
这样只查出14来
idhgd 2011-03-31
  • 打赏
  • 举报
回复
set rs=conn.execute("select * from aaa where instr('12,14,16',',' & id & ',')>0")
这样?
wwwwb 2011-03-31
  • 打赏
  • 举报
回复
select * from aaa where instr('12,14,16',',' & id & ',')>0
准确查找
idhgd 2011-03-31
  • 打赏
  • 举报
回复
sql="select * from aaa where instr('12,14,16',id)>0"
使用这个会把ID为2,4,6,1的数据也查询出来
idhgd 2011-03-31
  • 打赏
  • 举报
回复
sql="select * from aaa where instr('1,2,3',id)>0"
试了好像不行,不明原因。用split函数数组字符串后循环实现。
加载更多回复(3)

7,714

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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