中国农业科学 小木虫:有一段查询的ASP代码,请高手解释下。

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/02 15:51:37
<%
getcondition = replace(trim(request("condition")),"'","''")
getkey = replace(trim(request("key")),"'","''")
If(Session("StuID") = "")Then
Response.Redirect("Index.asp")
Response.End()
End If
if(getcondition = "" or getkey = "")then
rssql = "Select * from tb_StuResult where stu_id='"&session("StuID")&"' order by res_subdate Desc"
else
If(InStr(getcondition,"res_subdate") > 0)Then
If(InStr(getkey,"-") > 0)Then
darray = Split(getkey,"-")
getkey = ""
For a=0 To Ubound(darray)
If(len(darray(a)) = 1 )Then
darray(a) = "0"&darray(a)
End If
getkey = getkey&darray(a)&"-"
Next
getkey = Mid(getkey,1,len(getkey)-1)
End If
rssql = "select * from tb_StuResult where convert(varchar(10),"&getcondition&",121) like '%"&getkey&"%' and stu_id='"&session("StuID")&"' order by res_subdate Desc"
Else
rssql = "Select * from tb_StuResult where "&getcondition&" like '%"&getkey&"%' and stu_id='"&session("StuID")&"' order by res_subdate desc"
End If
end if

注意以下内容:
1. replace()替换,trim()压缩空格
2. session()值
3. instr()字符串比较
4. split(),Ubound(),Lbound(),数据分离
成数组,上下标,及数据统一长度并重新组合,去除尾部符号
5. 根据不同情况查询语句不一.

分太少了,

不过要注意的楼上的说的差不多了,就是字符串的处理而已,代码太长不想一句一句解释了