asp 模糊查询 求助高手。//。。。/?

来源:百度知道 编辑:UC知道 时间:2024/05/11 01:36:54
set rssos=server.CreateObject("adodb.recordset")

sqlstr="select * from xxxx where id<>0 "
if key<>"" then
sqlstr=sqlstr & " and name and xinghao '%" & key & "%'"
end if
if key2<>"" then
sqlstr=sqlstr & " and 11 like '%" & key2 & "%'"
end if
if key3<>"" then
sqlstr=sqlstr & " and 22 like '%" & key3 & "%'"
end if

sqlstr=sqlstr & " order by id desc"
'response.write sqlstr

rssos.Open sqlstr,conn,1,1

主要是这一句:
sqlstr=sqlstr & " and name and xinghao '%" & key & "%'"

有错误。
只能查NAME的,如果XINGHAO放前面,就只能查XINGHAO,请高手指点。。。

1,sqlstr=sqlstr & " and name like '%" & key & "%' and xinghao like '%" & key & "%'"

2,sqlstr=sqlstr & " and (name like '%" & key & "%' or xinghao like '%" & key & "%')"
不知道你要哪种情况,大概就是这样

sqlstr=sqlstr & " and name and xinghao like '%" & key & "%'"

少了LIKE

(NAME AND XINGHAO) 用括号括起来

说的不清