Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/03/2005, 09:33
sqa212
 
Fecha de Ingreso: mayo-2003
Mensajes: 866
Antigüedad: 22 años
Puntos: 0
listado con suma de campos registros anteriores

Estoy intentando hacer este listado, cuando se produce una alta o una baja dependiendo de
si el socio es un hombre o una mujer se inserta en la base de datos un valor en los campos
balanceM y balanceH, de la siguiente forma:
Alta:
si es un hombre balanceM=0 y balanceH=1
si es una mujer balanceM=1 y balanceH=0
Baja:
si es un hombre balanceM=0 y balanceH=-1
si es una mujer balanceM=-1 y balanceH=0

Estas variables muestran los valores de lo que ha supuesto la aportacion individual de
cada individuo al Total de hombres (TOTALH) y al total de mujeres (TOTALM).

Las variablEs TOTALH Y TOTALM intento que recojan los resultados acumulados.
Los resultados estan paginados de 25 en 25, el problema es que estas variables
vuelven a inicializarse en cada pagina, mostrando tan solo el acumulado de los registros mostrados
en cada pagina, en lugar de tambien tener en cuenta los registros precedentes.

¿Podria modificar la consulta poniendo Sum (balanceM) As TOTALM y Sum (balanceH) As TOTALH?
Creo que si pero no se como seria la forma correcta de realizar la consulta.
¿Se os ocurre otra forma?

El archivo db.asp contiene:
<!-- #include file="adovbs.inc" -->
<%
dim db
dim strConn
strConn = "sociosconn"
Set db = Server.CreateObject("ADODB.Connection")
db.open strConn
%>


<%@ LANGUAGE = "VBScript" %>
<!-- #include file="db.asp" -->
<%Response.expires=-1500%>
<html lang="ES">
<head>
<META HTTP-EQUIV="expires" content="0">
<META HTTP-EQUIV="cache-control" content="no-cache">
<META HTTP-EQUIV="pragma" content="no-cache">
<LINK href="estilos.css" rel=stylesheet>
</head>
<body link="#000000" vlink="#000000" alink="#000000">
<table border="0,2" bordercolor="#000000" align="center">
<tr>
<td align="center" class="textopeqcolor">
<b>NUMERO DE SOCIO</b></td>
<td valign="top" align="center" class="textopeqcolor">
<b>Balance</b><br><br>
<table width="10%">
<tr><td align="center" class="textopeqcolor">
<b>HOMBRES</b></td>
<td align="center" class="textopeqcolor">
<b>MUJERES</b></td>
</tr>
</table>
</td>
<td valign="top" align="center" class="textopeqcolor">
<b>TOTAL</b><br><br>
<table width="10%">
<tr><td align="center" class="textopeqcolor">
<b>HOMBRES</b></td>
<td align="center" class="textopeqcolor">
<b>MUJERES</b></td>
</tr>
</table>
</td>
</tr>
<%
DIM mySQL, objRS
mySQL = "SELECT * FROM SOCIOS ORDER BY idocio ASC"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorType = 1
objRS.Open mySQL, db

DIM intPageRecords, intRecords, intRecordCount, intCurrentPage
DIM intNumberOfPages, intDisplayPage
intPageRecords = Request.Querystring("pagina")
IF intPageRecords = "" THEN intPageRecords = 1 : intRecords = 1
intRecords = intPageRecords
intPageRecords = ((intPageRecords - 1) * 25) +1
intRecordCount = 0
IF NOT objRS.EOF THEN
objRS.Move (intPageRecords - 1)
DO WHILE intRecordCount < 25 and NOT objRS.EOF
%>
<tr>
<td align="center" class="textopeq">
<b><%=objRS("nidentificacion") %></b>&nbsp;&nbsp;&nbsp;
</td>
<td align="center" class="textopeq">
<table width="10%">
<tr>
<td align="center" class="textopeq">
<b><%=objRS("balanceM") %></b>
</td>
<td align="center" class="textopeq">
<b><%=objRS("balanceH") %></b>
</td>
</tr>
</table>
</Td>
<td align="center" class="textopeq">
<table width="10%">
<tr>
<td align="center" class="textopeq">
<%TOTALM=TOTALM+objRS("balanceM") %>
<b><%=TOTALM%></b>
</td>
<td align="center" class="textopeq">
<%TOTALH=TOTALH+objRS("balanceH")%>
<b><%=TOTALH%></b>
</td>
</tr>
</table>
</Td>
<%
objRS.MoveNext
intRecordCount = intRecordCount +1
Loop
END IF
%>
</table>
<table align="center">
<tr><td>
<br>
<b>
Mostrando desde el registro Nº
<%=intPageRecords%>
hasta el registro Nº
<%=intPageRecords+(intRecordCount-1)%>
<br>
<center>Total Registros:
<%=(objRS.RecordCount)%>
</center>
</b>
<p>
</td></tr>
</table>
<table align="center">
<tr><td>
<b>
<%
intCurrentPage = Request.Querystring("pagina")
IF intCurrentPage = "" THEN intCurrentPage = 1
intNumberOfPages = int(objRS.RecordCount \ 25)
IF objRS.RecordCount MOD 25<> 0 THEN intNumberOfPages = intNumberOfPages + 1
Response.Write("Página: [")
FOR intDisplayPage = 1 TO intNumberOfPages
IF Cint(intDisplayPage) = Cint(intCurrentPage) THEN
Response.Write " <b>" & intDisplayPage & "</b> "
ELSE
Response.Write " <a href=""liSTSUM.asp?pagina=" & intDisplayPage & """>" & intDisplayPage &_
"</a> "
END IF
NEXT
Response.Write ("]")
%>
</b>
</td></tr>
</table>
</body>
</html>
<%
db.close
set db=nothing
%>