注册 登录
编程论坛 ASP技术论坛

使用union后如何提取记录总数以及如何选取top5?

liu_libra 发布于 2012-03-28 16:16, 429 次点击
在网上搜索的结果是
select count(*) from (select a  from tableA  union select a  from tableB )
但是在asp里如何输入记录数呢?
<%set rs=server.CreateObject("adodb.recordset")
      sql="select count(a) from (select a  from tableA  union select a  from tableB ) "
      rs.open sql,conn,1,3
%>  <%=rs("count(a)")%>   
这样无法输出结果,请走过路过的朋友指点迷津!

另外使用union后如何提取前5项,是这样吗?  sql="select top 5 * from (select a  from tableA  union select a  from tableB ) "
2 回复
#2
cnfarer2012-03-28 20:39
"select count(a) from ……"  ==>  "select count(a) n from ……"
 <%=rs("count(a)")%>  ==>   <%=rs("n")%>
#3
liu_libra2012-03-29 12:24
n是什么意思,好像不行啊,版主
1