28,406
社区成员
发帖
与我相关
我的任务
分享
<%
dim count,rs,i
set rs=server.CreateObject("ADODB.RecordSet")
for i=1 to 30
'取单位相同的信息统计共有多少条
sql="SELECT COUNT(Id) FROM kaohe WHERE (workid="&i&" OR workid=11) AND nianfen LIKE '%2009%'"
count=conn.execute(sql)(0)
if count="" then count=0
err.clear
sql=""
'判断该单位是否已经存在于统计表内
set rs=conn.execute("SELECT workid FROM kaohetongji WHERE workid="&i)
if rs.eof and rs.bof then'如果不存在就写入新数据
sql="INSERT INTO kaohetongji (workid,nianfen,tongji) VALUES('"&i&"','"&2009&"','"&count&"')"
else'如果存在就更新其数据
sql="UPDATE kaohetongji SET tongji=count WHERE workid="&i
end if
if rs.state<>0 then rs.close
if sql<>"" then conn.execute(sql)
if err then'如果出错,提示并跳出循环
response.write"<script>alert('"&err.description&"')</script>"
exit for
end if
next
set rs=nothing
conn.close:set conn=nothing
%>
<%
dim count,rs,i
'取你要的数字
sql="SELECT COUNT(Id) FROM kaohe WHERE (workid=1 OR workid=11) AND nianfen LIKE '%2009%'"
count=conn.execute(sql)(0)
if count="" then count=0
err.clear
set rs=server.CreateObject("ADODB.RecordSet")
sql="SELECT * FROM kaohe ORDER BY Id DESC"
rs.open sql,conn,1,1
for i=1 to 30'这个30是怎么回事?
'更新【kaohetongji】
sql="UPDATE kaohetongji SET workid=i,nianfen=2009,tongji=count WHERE workid='' OR workid IS NULL"
conn.execute(sql)
sql="UPDATE kaohetongji SET tongji=count WHERE workid="&i
conn.execute(sql)
if err then'如果出错,提示并跳出循环
response.write"<script>alert('"&err.description&"')</script>"
exit for
end if
rs.movenext
next
rs.close: set rs=nothing
conn.close:set conn=nothing
%>
<%
dim count,rs,i'''''''''''''''''''''',rs1,i
'换个方式取你要的数字
sql="SELECT COUNT(Id) FROM kaohe WHERE (workid=1 OR workid=11) AND nianfen LIKE '%2009%'"
count=conn.execute(sql)(0)
if count="" then count=0
err.clear
set rs=server.CreateObject("ADODB.RecordSet")
''''''''''''''''''''''''''''''''set rs1=server.createobject("adodb.recordset")
'''''''rs.Source="select * from kaohe order by ID DESC"
'''''''rs.Open rs.Source,conn,1,1
sql="SELECT * FROM kaohe ORDER BY Id DESC"
rs.open sql,conn,1,1
for i=1 to 30'这个30是怎么回事?
''''''''''''rs.movefirst
''''''''''''count=0
''''''''''''while not rs.eof
''''''''''''if (trim(rs("workid"))="1" or trim(rs("workid"))="11") and trim(year(rs("nianfen")))=2009 then ''''''''''''count=count+1
''''''''''''rs.movenext
'''''''''''''wend
'''''''''''''''''''''''''' set rs1=server.createobject("adodb.recordset")'set放这里不是要创建30次?移出到循环外
''''''''sql="select * from kaohetongji where (id is null)"'这个是什么意思?
'''''''''rs1.open sql,conn,1,3
'''''''''if rs1("workid")="" then
'''''''''rs1.addnew
'''''''''rs1("workid")=i
'''''''''rs1("nianfen")=2009
''''''''''rs1("tongji")=count
''''''''''rs.update怎么UPDATE了rs??
'更新【kaohetongji】
sql="UPDATE kaohetongji SET workid=i,nianfen=2009,tongji=count WHERE workid='' OR workid IS NULL"
conn.execute(sql)
sql="UPDATE kaohetongji SET tongji=count WHERE workid="&i
conn.execute(sql)
'''''''''''else
''''''''''''sql="select * from kaohetongji where workid="&i
''''''''''''rs1.open sql,conn,3,3
''''''''''''rs1("tongji")=count
''''''''''''rs1.update
''''''''''''end if
''''''''''''rs1.close
''''''''''''set rs1=nothing
'''''''rs.close还在用啊,怎么在循环里面就关了呢
'''''''set rs=nothing还在用啊,怎么在循环里面就nothing了呢
''''''''i=i+1在for循环里怎么还i=i+1?是想隔一处理一条吗?
next
''''''''''''''''''''''rs1.close
''''''''''''''''''''''set rs1=nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
%>