请问这个查询语句写法存在什么问题吗?
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吗?