日期:2014-05-17  浏览次数:21046 次

大家看看一个if语句为什么不正确?
<%
dim   channel
dim   order
channel=trim(request( "channel "))
order=trim(request( "order "))
dim   sql
dim   rs
set   rs=server.createobject( "adodb.recordset ")  
If   channel <> " "   then
sql   = "select   top   100   *   from   tab1   where   channel= ' "&channel& " '   order   by   writetime   Desc "  
else
sql   = "select   top   100   *   from   tab1   "  
If   order= "good "   Then
sql=sql& "   order   by   score   desc "
Else   If   order= "bad "   Then
sql=sql& "   order   by   score   asc "
else
sql=sql& "   order   by   datetime   Desc "
End   if
end   if
rs.open   sql,conn,1,1
%>
======================
这个句子channel <> " "似乎有错。我用链接打开http://XXX/X.asp?order=good或order=bad或x.asp都是正确的。
但是这样X.asp?channel=XX   就没有结果了。不过如果不用if语句,只用:
sql   = "select   top   100   *   from   tab1   where   channel= ' "&channel& " '   order   by   writetime   Desc "  
完全正常。表明SQL语句是正常的,问题应该出在If   channel <> " "   then   这里,请高人指点?


------解决方案--------------------
好象应该是 channel <> " " ,为了保险可以多加些条件
If isnull(channel) or channel <> " " or channel <> " " then
------解决方案--------------------
if len(channel) > 0 then

另外这句Else If order= "bad " Then

应该是 ElseIf order= "bad " Then 吧?

------解决方案--------------------
If channel <> " " or isnull(channel) then
sql = "select top 100 * from tab1 where channel= ' "&channel& " ' order by writetime Desc "
else
sql = "select top 100 * from tab1 "
end if '判断channel的情况


If order= "good " or order= "bad " Then
sql=sql& " order by score desc "
esle
sql=sql& " order by datetime Desc "
end if '判断order的情况