请问这个查询语句写法存在什么问题吗?

szlzc 2003-08-27 09:15:18
我在用asp+server2000写网页的时候,需要根据某些条件用查询语句来列出结果。
<%
dim sql
dim rs
set conn=Server.CreateObject("ADODb.Connection")
Set rs= Server.CreateObject("ADODb.Recordset")
conn.open "driver={SQL Server};server=server;uid=sa;pwd=aa;database=bb"
sql="select * from VopMSsql where eid='"&session("pin")&"' and hourofday<>''and minuteofhour<>''order by id desc"
response.write sql
rs.open sql,conn,1,3
if rs.eof and rs.bof then
response.write "<tr><td colspan='4' align='center'><font size='3' color='red'>没有信息!</td></tr>"
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
%>
<%
do while not rs.eof
%>
<tr>
<td><%=rs("yearfrom")%></td>
<td><%=rs("yearto")%>年</td>
<td><%=rs("hourofday")%></td>
<td><%=rs("minuteofhour")%></td>
</tr>
<%
rs.movenext
loop
%>
我想把数据库中所有符合条件的记录都列出来,但上面的sql语句只是列出最后一条记录,如果我把上面的sql语句改为:sql="select * from VopMSsql where eid='"&session("pin")&"' and hourofday<> order by id desc" 就能正确表达我的意思,全部列出符合条件的记录,请问问题出现在哪里,怎么解决呢?如果后面的条件更多,怎么办?sql查询的where条件不能多带几个and吗?
...全文
16 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowJP 2003-08-27
  • 打赏
  • 举报
回复
sql="select * from VopMSsql where eid='"&session("pin")&"' and hourofday is not nul and minuteofhour is not null order by id desc"

试试看
kongming6926 2003-08-27
  • 打赏
  • 举报
回复
你上面的程序好象会出错:缺少一个else,不然是先关了rs ,conn再读数据能不出错?
61 2003-08-27
  • 打赏
  • 举报
回复
<%
dim sql
dim rs
set conn=Server.CreateObject("ADODb.Connection")
Set rs= Server.CreateObject("ADODb.Recordset")
conn.open "driver={SQL Server};server=server;uid=sa;pwd=aa;database=bb"
sql="select * from VopMSsql where eid='"&session("pin")&"' and (hourofday<>'' or (hourofday is not null)) and (minuteofhour<>'' or (minuteofhour is not null)) order by id desc"
rs.open sql,conn,1,3
if not rs.eof then
while not rs.eof
%>
<tr>
<td><%=rs("yearfrom")%></td>
<td><%=rs("yearto")%>年</td>
<td><%=rs("hourofday")%></td>
<td><%=rs("minuteofhour")%></td>
</tr>
<%
rs.movenext
wend
%>
else
response.write "<tr><td colspan='4' align='center'><font size='3' color='red'>没有信息!</td></tr>"
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

wolf004 2003-08-27
  • 打赏
  • 举报
回复
语句正确的!没什么问题!
有可能是你的条件数据只有最后一条!
where里的and多几个是没有关系的!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧