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

SQL

guang2356447 发布于 2007-10-26 11:46, 460 次点击

字段 name age hao
sdf asdf 23
asdf asdf 23
asfd sfd 23
asdf asdf 56
asdf asf 56
safd fd 56

用SQL
怎么显示hao 为23 的总记录 就是hao为23 的有几条

[此贴子已经被作者于2007-10-26 11:48:16编辑过]

8 回复
#2
madpbpl2007-10-26 12:55

sql ="select * from [tablename] where hao='23'"

#3
guang23564472007-10-26 13:57
madpbpl
感谢

可能你没明白我的意思

我的意思是 在字段hao中 为23的值有几条
比如有2条就显示2

怎么写SQL
#4
永夜的极光2007-10-26 14:02
select count(*) as c from [tablename] where hao='23'
#5
guang23564472007-10-26 16:40
<%
conn.execute("select count(hao) as ccc from aaa where hao='43'")
%>
上面这句没错误
但是不显示数子啊
我使用<%=ccc%>也不显示 怎么回事 到底怎么用
#6
qhscqb2007-10-26 16:51
用这种方法:
set rs_count=server.createobject("adodb.recordset")
rs_count.open "select * from [tablename] where hao='23'",conn,1,1
response.write "hao字段中有" &rs_count.recordcount& "条记录<br>"
rs_count.close
set rs_count=nothing
#7
guang23564472007-10-26 16:58

感谢 qhscqb 永夜的极光 madpbpl
可以了
<%
set rs2=server.CreateObject("adodb.recordset")
exec="select * from aaa where hao='44'"
rs2.open exec,conn,1,1
%>
<%=rs2.recordcount%>

结帖

#8
madpbpl2007-10-26 20:28
以下是引用guang2356447在2007-10-26 16:40:24的发言:
<%
conn.execute("select count(hao) as ccc from aaa where hao='43'")
%>
上面这句没错误
但是不显示数子啊
我使用<%=ccc%>也不显示 怎么回事 到底怎么用

最好不要用conn.execute,如果用了以后要用rs.getrows()来得到你要的记录
不然你只能得到-1。

#9
ming2062007-10-27 11:52
从效率上讲,4楼的应该是最高的.
1