帮写个ASP一表多字段搜索代码

来源:百度知道 编辑:UC知道 时间:2024/06/21 07:48:28
如题,请大虾帮忙写个搜索代码;
表名:chanpin1
----------------
作用 字段
产地:Origin
年份:YearWere
价格:Price
类别:fatherID(数字)
名称:mingcheng1

帮写一个可以根据以上选项一个或多个(或全部)条件对数据库表chanpin1中的数据进行搜索查询。
补充:价格的查询条件是一个价格至一个价格这间的数据,例如:100-300
哎,没人帮我,哎哎;惟有关闭!

sql="select * from chanpin1 where 1=1"
if Origin<>"" then
sql=sql&" and Origin='"&Origin&"'"
end if
if YearWere<>"" then
sql=sql&" and YearWere='"&YearWere&"'"
end if
if Price1<>"" and Isnumeric(YearWere) and Price2<>"" and isnumeric(Price2) then
sql=sql&" and Price>="&price1&" and Price<="&Price2&""
end if
if fatherID<>"" and isnumeric(fatherID) then
sql=sql&" and fatherID="&fatherID&""
end if
if mingcheng1<>"" then
sql=sql&" and mingcheng1='"&mingcheng1&"'"
end if
如果需要模糊搜索自己加个%%就是了