用下面这个ASP的子程序生成WHERE条件就可以了,这个程序是我从动网论坛的程序中找的,我只是加了个把全角空格改半角的语句。
用它非常的方便,可以支持空格、OR、AND等条件,慢慢研究吧。祝你好运~~
------------------------------------------------------
public function translate(sourceStr,fieldStr)
rem 处理逻辑表达式的转化问题
dim sourceList
dim resultStr
dim i,j
sourceStr=replace(sourceStr," "," ")
if instr(sourceStr," ")>0 then
dim isOperator
isOperator = true
sourceList=split(sourceStr)
'--------------------------------------------------------
rem Response.Write "num:" & cstr(ubound(sourceList)) & "<br>"
for i = 0 to ubound(sourceList)
rem Response.Write i
Select Case ucase(sourceList(i))
Case "AND","&","和","与"
resultStr=resultStr & " and "
isOperator = true
Case "OR","|","或"
resultStr=resultStr & " or "
isOperator = true
Case "NOT","!","非","!","!"
resultStr=resultStr & " not "
isOperator = true
Case "(","(","("
resultStr=resultStr & " ( "
isOperator = true
Case ")",")",")"
resultStr=resultStr & " ) "
isOperator = true
Case Else
if sourceList(i)<>"" then
if not isOperator then resultStr=resultStr & " and "
if inStr(sourceList(i),"%") > 0 then
resultStr=resultStr&" "&fieldStr& " like '" & replace(sourceList(i),"'","''") & "' "
else
resultStr=resultStr&" "&fieldStr& " like '%" & replace(sourceList(i),"'","''") & "%' "
end if
isOperator=false
End if
End Select
rem Response.write resultStr+"<br>"
next
translate=resultStr
else '单条件
if inStr(sourcestr,"%") > 0 then
translate=" " & fieldStr & " like '" & replace(sourceStr,"'","''") &"' "
else
translate=" " & fieldStr & " like '%" & replace(sourceStr,"'","''") &"%' "
End if
rem 前后各加一个空格,免得连sql时忘了加,而出错。
end if
end function
----------------------------------------------------