当前位置:编程学习 > VB >>

请帮忙修改一下VB中的SQL语句

下面这个是出现错误的语句:

" select * from tblcpzl where 产品名称 like '" * " & " & Me.cxnr & " & " * "'"


下面这个是正确的语句,但是没有"*"

" select * from tblcpzl where 产品名称 like '" & Me.cxnr & "'"


我想建立一个模糊查询,就想到了 like *某某产品* 的形式,请帮忙改一下第一句。

--------------------编程问答--------------------
" select * from tblcpzl where 产品名称 like '*" & Me.cxnr & "*'"
--------------------编程问答-------------------- 你的SQL语句本身是错的,不管在什么系统中都不能返回你预期的结果。这不是VB的问题。
你还是先把SQL语句弄对了再说 --------------------编程问答--------------------
"select * from tblcpzl where 产品名称 like '% "  & Me.cxnr  & " % '"
--------------------编程问答--------------------
'参考

SQL = "select 序号,工序类别,工序名称,计件单位,工价,是否停用 from WPI"
SQL = SQL & " where 工序类别 & 工序名称 & 计件单位 & 工价 like '%" & Replace(Text1.Text, "'", "''") & "%' and 是否停用=0"
--------------------编程问答-------------------- 看看这里:
http://topic.csdn.net/u/20080927/04/DA048AF0-F6DF-423B-9809-E659F1E05854.html --------------------编程问答--------------------
引用 3 楼 lb_bn 的回复:
VB code
"select * from tblcpzl where 产品名称 like '% "  & Me.cxnr  & " % '"


多了两个空格

这样
"select * from tblcpzl where 产品名称 like '%" & Me.cxnr & "% '"
--------------------编程问答-------------------- 模糊查询用的是%不是* --------------------编程问答-------------------- jhone99兄是SQL语句高手啊! --------------------编程问答--------------------
引用 7 楼 robinpipi 的回复:
模糊查询用的是%不是*

+1
楼主以为自己在使用Windows.... --------------------编程问答-------------------- ACCESS环境中可以如下:
" select * from tblcpzl where 产品名称 like '*" & Me.cxnr & "*'"
VB6下ADO不认*,要用%:
" select * from tblcpzl where 产品名称 like '%" & Me.cxnr & "%'"
--------------------编程问答-------------------- ......
顶一下。 --------------------编程问答-------------------- 请先说明SQL的使用地方
Access
SQLServer
DB2
等等。
模糊查询的表示方法不一样。 --------------------编程问答-------------------- select * from tblcpzl where 产品名称 like '%%" & Me.cxnr & "%% '"
--------------------编程问答-------------------- 必须加两个 %% --------------------编程问答-------------------- "select * from tblcpzl where 产品名称 like '% "  & Me.cxnr  & " % '"
"select * from tblcpzl where 产品名称 like '* "  & Me.cxnr  & " * '"
这两个总有一个是对的,一般的前一个,但有是用后一个,其实我常常将“&”改为“+”,都是没问题的 --------------------编程问答-------------------- oo upuppu --------------------编程问答-------------------- --------------------编程问答-------------------- 请先说明SQL的使用地方
Access
SQLServer
DB2
等等。
模糊查询的表示方法不一样。 --------------------编程问答-------------------- " select * from tblcpzl where 产品名称 like '*" & Me.cxnr & " *'"
这么写应该是正确的!                                   
补充:VB ,  VBA
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,