请教一个低级asp中写多条SQL语句的问题,谢谢大家~

yinxun 2013-11-20 10:21:49
假设有数据库如下:

张三 男 39岁
李四 男 42岁
马五 男 32岁
牛二 女 31岁
胡一 女 21岁


如果现在让我把这张表展示在asp页面上我会,写个sql,select * from table,然后用循环语句把每条记录展示出来就行了
……
sql="select * from [btxh] order by usertime desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1

……
Response.write("<table border=1 width='90%' cellspacing=1 align=center cellpadding=3 bordercolor=#ad8c42 style=BORDER-COLLAPSE: collapse;><tr><td align=center width='25%'><b>姓名</b></td><td align=center width='25%'><b>性别</b></td><td align=center width='25%'><b>年龄</b></td></tr>")

while (not rs.eof) and (not page_count = rs.pagesize)

dim x_xingming,x_xingbie,x_nianling

x_xingming =rs("xingming")
x_xingbie = rs("xingbie")
x_nianling = rs("nianling")
%>

<a id="msg<%=rs("id")%>">



<tr class="title2" align="center">
<td>
<% response.write x_xingming %>
</td>
<td>
<% response.write X_xingbie %>
</td>
<td>
<% response.write X_nianling %>
</td>
</tr>


<%
page_count = page_count + 1
rs.movenext
wend
%>
</table>
……




但现在我要实现如下目的:
在asp页面中用文字显示出来


本表共有5条记录,其中男性3名,女性2名,30岁以上4名,30岁以下1名……

这些5 3 2 4 1这些数字都是sql语句算出来的,其他中文的文字都是事先写好的

相当于要调用5个SQL语句
select count(*) from table
select count(*) from table where xingbie = "男"
select count(*) from table where xingbie = "你"
select count(*) from table where nianling > 30
select count(*) from table where nianling < 30


请问同时调用多个sql语句,这个asp代码怎么写呢?

我是初学者,可以看懂代码,但不会写,现在只会下些源代码下来自己看看为自己所用,所以麻烦大侠们写详细一点哦,谢谢~

谢谢大家~
...全文
335 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2013-11-21
  • 打赏
  • 举报
回复
不用执行那么多sql语句吧,直接sql="select * from [btxh] order by usertime desc"就行了,自己用asp统计一下,要不就一次创建一个游标来获取记录集 一次性统计需要改下循环结构 totalrecord=rs.recordcount male=0 female=0 age30up=0 age30down=0 while (not rs.eof) if rs("xingbie")="男" then male=male+1 else female=female+1 end if if cint(rs("nianling"))>30 then age30up=age30up+1 else age30down=age30down+1 end if if (not page_count = rs.pagesize) then''''''''输出内容 dim x_xingming,x_xingbie,x_nianling x_xingming =rs("xingming") x_xingbie = rs("xingbie") x_nianling = rs("nianling") %> <a id="msg<%=rs("id")%>"> <tr class="title2" align="center"> <td> <% response.write x_xingming %> </td> <td> <% response.write X_xingbie %> </td> <td> <% response.write X_nianling %> </td> </tr> <% end if page_count = page_count + 1 rs.movenext wend %> </table>
yinxun 2013-11-21
  • 打赏
  • 举报
回复
不好意思,补充一下 是access的
hookee 2013-11-21
  • 打赏
  • 举报
回复
sql server的话 <% ... sql = "select count(*) from table;select count(*) from table where xingbie = '男';select count(*) from table where xingbie = '你';select count(*) from table where nianling > 30;select count(*) from table where nianling < 30;" Set rs = CreateObject("Adodb.RecordSet") rs.open sql,conn,1,1 Response.Write rs(0) Set rs1 = rs.NextRecordSet Response.Write rs1(0) Set rs1 = rs.NextRecordSet Response.Write rs1(0) Set rs1 = rs.NextRecordSet Response.Write rs1(0) Set rs1 = rs.NextRecordSet Response.Write rs1(0) If rs1.State<>0 Then rs1.Close Set rs1 = Nothing If rs.State<>0 Then rs.Close Set rs = Nothing conn.close Set conn = Nothing %>

28,391

社区成员

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

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