标题:求~~~~助!
只看楼主
从零开始
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2004-11-3
 问题点数:0 回复次数:8 
求~~~~助!
<%
Set cn=Server.CreateObject("ADODB.Connection")
cn.ConnectionString="DSN=weisheng;UID=sa;PWD=transit"
cn.open
Set rs=Server.CreateObject("ADODB.Recordset")
Source="Select Num,Count(Num) from card1 where (Time2-Time1)=0 group by Num"
Source="Select Num,Count(Num) from card1 where (Time2-Time1)=1 group by Num"
rs.Open source,cn
Response.Write"<TABLE BORDER ALIGN=CENTER>"
Response.Write"<TR>"
Response.Write"<TD>地区编码</TD>"
Response.Write"<TD>0天</TD>"
Response.Write"<TD>1天</TD>"
DO While Not rs.Eof
    Response.Write"<TR>"
 For I=o to rs.Fields.Count-1
      Response.Write"<TD>"&rs(I).Value&"</TD>"
 NEXT
 rs.MoveNext
LOOP
rs.Close
cn.Close
Set rs=Nothing
Set cn=Nothing
%>  
想一次统计出TIME2-TIME=0和1两个情况的记录数目,象上面那样写只能的到0的```1的是空白,该怎么办??
搜索更多相关主题的帖子: source where 
2004-11-12 09:47
从零开始
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2004-11-3
得分:0 

上面得到的是1的COUNT数~~0的不能显示出来,而且1的数目显示在0的表下面

2004-11-12 09:50
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
得分:0 

For I=o to rs.Fields.Count-1 '应该为0

Response.Write"<TABLE BORDER ALIGN=CENTER>" Response.Write"<TR>" Response.Write"<TD>地区编码</TD>" Response.Write"<TD>0天</TD>" Response.Write"<TD>1天</TD>" response.write"</TR>" '行都没有结束

Response.Write"<TR>" DO While Not rs.Eof For I=o to rs.Fields.Count-1 '应该为0 Response.Write"<TD>"&rs(I).Value&"</TD>" NEXT rs.MoveNext LOOP response.write"</TR>" '一样没有结束

Source="Select Num,Count(Num) from card1 where (Time2-Time1)=0 group by Num" Source="Select Num,Count(Num) from card1 where (Time2-Time1)=1 group by Num" '可以这样字写两条SQL语句同时执行吗??? 分开用两个记录集来显示好些啊!


最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2004-11-12 10:18
从零开始
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2004-11-3
得分:0 

怎么分开呢?我想并排显示啊```地区编号 0天 1天

XXXXXX 4 5

2004-11-12 10:25
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
得分:0 
Source="Select Num,Count(Num) from card1 where (Time2-Time1)=0 group by Num" Source2="Select Num,Count(Num) from card1 where (Time2-Time1)=1 group by Num" ....... Response.Write"<TD>"&rs(I).Value&"</TD>" Response.Write"<TD>"&rs2(I).Value&"</TD>"

最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2004-11-12 10:37
从零开始
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2004-11-3
得分:0 
不好用``SOURCE2都不识别,颜色都不变
2004-11-12 11:30
从零开始
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2004-11-3
得分:0 
继续求````
2004-11-12 13:48
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 
把最终表格效果画一下!

天津网站建设 http://www./
2004-11-12 16:56
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

没找到什么好办法,我只能做到这样了,建一个存储过程,但只能返回固定天数的数据(列数固定)

CREATE PROCEDURE MyProc AS declare @num int DECLARE num_cursor CURSOR FOR SELECT distinct num FROM card1 OPEN num_cursor FETCH NEXT FROM num_cursor INTO @num WHILE @@FETCH_STATUS = 0 BEGIN select @num as num,(select count(num) from card1 where num=@num and time2-time1=0) as day0,(select count(num) from card1 where num=@num and time2-time1=1) as day1 ,(select count(num) from card1 where num=@num and time2-time1=2) as day2 fetch next from num_cursor into @num END CLOSE num_cursor DEALLOCATE num_cursor GO

ASP程序如下: <% Dim cmd,rs,connstr

ConnStr="Provider=Sqloledb;User ID=sa;Password=;Initial Catalog=db;Data Source=(local)"

Set cmd=Server.CreateObject("ADODB.Command") Cmd.ActiveConnection = ConnStr '连接字符串 Cmd.CommandText = "MyProc" Cmd.CommandType = 4 'adCmdStoredProc Set rs = Cmd.Execute() response.write "<table border=1><tr><td>地区编码</td><td>0天</td><td>1天</td><td>2天</td></tr>" While Not rs Is Nothing If (Not rs.EOF) Then Response.write "<tr><td>" & rs(0) & "</td><td>" & rs(1) & "</td><td>" & rs(2) & "</td><td>" & rs(3) & "</td></tr>" End If Set rs = rs.NextRecordset() '下一记录集 Wend response.write "</table>" set rs=nothing set cmd=nothing %>

最终效果:

地区编码 0天 1天 2天
2 0 0 1
4 0 1 0
5 0 2 1
6 0 1 1

[此贴子已经被作者于2004-11-12 18:04:48编辑过]


天津网站建设 http://www./
2004-11-12 18:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-7511-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.525523 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved