<%
UpdateAllData()
DeleteEmptyData()

Sub UpdateAllData()
	set rs=server.CreateObject("adodb.recordset")
	sql="select titleID,titleCount,clickCount from title order by titleID desc"
	rs.open sql,conn,1,3
	do while not rs.eof 
		set rs1=conn.execute("select count(*),sum(click) from imgbook where titleID="&cint(rs("titleID")))
		rs(1)=cint(rs1(0))
		rs(2)=cint(rs1(1))
		rs.update
		rs.movenext
		rs1.close
	loop
	set rs1=nothing
	rsclose
End Sub

Sub DeleteEmptyData()
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from title where titleCount=0",conn,1,3
	do while not rs.eof 
		rs.delete
		rs.update
		rs.movenext
	loop
	rsclose
End Sub
%>