asp~~~急!!!

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:35:35
请问有没简单的代码可以代替下面的代码啊??

<%
pname=request("pname")
cj=request("cj")
yy=request("yy")
ywy=request("ywy")
s_date = trim(request("year2"))&"-"&trim(request("month2"))&"-"&trim(request("day2"))
e_date=trim(request("year3"))&"-"&trim(request("month3"))&"-"&trim(request("day3"))
set rs=server.createobject("adodb.recordset")

<!--1--4全部-->
if request("pname")<>"请选择" and request("cj")<>"请选择" and request("yy")<>"请选择" and request("ywy")<>"请选择" then
SQL =" select * from jia where pname='"&request("pname")&"' and cj='"&request("cj")&"' and yy='"&request("yy")&"' and ywy='"&reques

1、将“请选择”表单的值设置为空。
2、用变量代替需要变化的SQL查询语句。如第一句SQL可设置查询语句内片断为变量:
dim aaa,bbb,ccc,ddd,......
if request("ywy")<>"" then
aaa="pname='"&request("pname")&"' and "
end if
if request("cj")<>"" then
bbb="cj='"&request("cj")&"' and "
end if
if request("yy")<>"" then
ccc="yy='"&request("yy")&"' and "
end if
if request("ywy")<>0 then
ddd="ywy='"&request("ywy")&"' and "
end if
......等等,将所有request("xxx")全部设置

那么SQL语句可只写一句即可:

SQL =" select * from jia where "&aaa&bbb&ccc&ddd&" jdate between '"&s_date&"' and '"&e_date&"' order by ID DESC "

总之有多少个变量,你就可以在SQL语句中放入去多少个。
因为如果这些变量值为空,那么相关的查