add up for each date

P

PeterL

Hi,
I´ve the folloing code:
Code:
<%
pat = Request.Form("rapport")
Set vbalans = Server.CreateObject("ADODB.Connection")
vbalans.Provider = "Microsoft.Jet.OLEDB.4.0"
MdbFilePath = Server.MapPath("\vatskebalans\db\vbalans.mdb")
vbalans.ConnectionString = "Data Source='" & MdbFilePath & "'"
vbalans.open
strSQL = "SELECT f.FluidNamn, f.FluidID, v.Dag, v.PatID, v.Volym,
v.Energi," &_
" p.ftEnamn, p.ftFnamn FROM (tblVetskebalans v INNER JOIN
tblFluids f"&_
" ON v.FluidID = f.FluidID) INNER JOIN tblPersonuppgifter p
ON v.PatID = p.PatID" &_
" WHERE p.PatID = "& pat &""
Set rs1 = vbalans.Execute (strSQL)
'formatera till svensk personnummer
Function SvPnr(txt)
personnummer =Left(txt,6) & " - " & Right(txt,4)
SvPnr = personnummer
End Function
Function FirstVersal(txt)
versal = UCase(Left(txt,1)) & LCase(Right(txt, Len(txt)-1))
FirstVersal = versal
End Function
Response.Write SvPnr(rs1("PatID")) & "<BR>"
Response.Write "<B>" & FirstVersal(rs1("ftEnamn")) & ", " &
FirstVersal(rs1("ftFnamn")) & "</B><P><P><P>"
%>
<TABLE border=1>
<TR>
<TD><B>Datum</B></TD>
<TD><B>Vätska</B></TD>
<TD><B>Volym</B></TD>
<TD><B>Energi</B></TD>
</TR>
<%
v = 0
e = 0
dat = ""
Do While Not rs1.EOF
v = v + cint(rs1("Volym"))
e = e + cint(rs1("Energi"))
If dat <> CDate(rs1("Dag")) then
dat = CDate(rs1("Dag"))
Response.Write "<TR><TD>" & CDate(rs1("Dag"))& "</TD>"
Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
Response.Write "<TD>" & rs1("Volym") & "</TD>"
Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
Else
Response.Write "<TR><TD> </TD>"
Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
Response.Write "<TD>" & rs1("Volym") & "</TD>"
Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
End If
rs1.MoveNext
Loop

vbalans.Close
Set vbalans = Nothing
%>
</TABLE>
<BR><BR><BR>
<%
Response.Write "<B><U>Totala volymen är</U></B>" & ":     " & v &
"<BR>"
Response.Write "<B><U>Totala energi är</U></B>" & ":        " & e &
"<BR>"
and this give the folling printout:
111111 - 1111
Elvansson, Elvan
Datum Vätska Volym Energi
2004-03-21 Blod 1000 0
Sondmat 550 275
Sondmat 550 275
Sondmat 50 35
2004-04-29 Albumin 76 0
2004-05-02 Proviva 123 0

Totala volymen är: 2849
Totala energi är: 825

But I would like the add upp for each datum:
i.e 2004-03-21 totVolym= 2150 and energi = 585

Can you please help me with this code?
All help we´ll be appiciated
/Peter L
 
K

Ken Schaefer

Where do you want to put this total? As you are looping through your
records, just keep adding the values to a variable if the date is the same.

Cheers
Ken


: Hi,
: I´ve the folloing code:
Code:
<%
: pat = Request.Form("rapport")
: Set vbalans = Server.CreateObject("ADODB.Connection")
: vbalans.Provider = "Microsoft.Jet.OLEDB.4.0"
: MdbFilePath = Server.MapPath("\vatskebalans\db\vbalans.mdb")
: vbalans.ConnectionString = "Data Source='" & MdbFilePath & "'"
: vbalans.open
: strSQL = "SELECT f.FluidNamn, f.FluidID, v.Dag, v.PatID, v.Volym,
: v.Energi," &_
:          " p.ftEnamn, p.ftFnamn FROM (tblVetskebalans v INNER JOIN
: tblFluids f"&_
:           " ON v.FluidID = f.FluidID) INNER JOIN tblPersonuppgifter p
: ON v.PatID = p.PatID" &_
:           " WHERE p.PatID = "& pat &""
:   Set rs1 = vbalans.Execute (strSQL)
: 'formatera till svensk personnummer
: Function SvPnr(txt)
:       personnummer =Left(txt,6) & " - " & Right(txt,4)
:   SvPnr = personnummer
: End Function
: Function FirstVersal(txt)
:       versal = UCase(Left(txt,1)) & LCase(Right(txt, Len(txt)-1))
:   FirstVersal = versal
: End Function
:     Response.Write SvPnr(rs1("PatID")) & "<BR>"
:     Response.Write "<B>" & FirstVersal(rs1("ftEnamn")) & ", " &
: FirstVersal(rs1("ftFnamn")) & "</B><P><P><P>"
: %>
: <TABLE border=1>
:   <TR>
:     <TD><B>Datum</B></TD>
:     <TD><B>Vätska</B></TD>
:     <TD><B>Volym</B></TD>
:     <TD><B>Energi</B></TD>
:    </TR>
: <%
: v = 0
: e = 0
: dat = ""
:  Do While Not rs1.EOF
: v = v + cint(rs1("Volym"))
: e = e + cint(rs1("Energi"))
: If dat <> CDate(rs1("Dag")) then
: dat = CDate(rs1("Dag"))
:        Response.Write "<TR><TD>" & CDate(rs1("Dag"))& "</TD>"
:        Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
:        Response.Write "<TD>" & rs1("Volym") & "</TD>"
:        Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
:  Else
:        Response.Write "<TR><TD> </TD>"
:        Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
:        Response.Write "<TD>" & rs1("Volym") & "</TD>"
:        Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
: End If
: rs1.MoveNext
: Loop
:
: vbalans.Close
: Set vbalans = Nothing
:  %>
: </TABLE>
: <BR><BR><BR>
: <%
: Response.Write "<B><U>Totala volymen är</U></B>" & ":     " & v &
: "<BR>"
: Response.Write "<B><U>Totala energi är</U></B>" & ":        " & e &
: "<BR>"
:
: and this give the folling printout:
: 111111 - 1111
: Elvansson, Elvan
: Datum Vätska Volym Energi
: 2004-03-21 Blod 1000 0
: Sondmat 550 275
: Sondmat 550 275
: Sondmat 50 35
: 2004-04-29 Albumin 76 0
: 2004-05-02 Proviva 123 0
:
: Totala volymen är: 2849
: Totala energi är: 825
:
: But I would like the add upp for each datum:
: i.e 2004-03-21 totVolym= 2150 and energi = 585
:
: Can you please help me with this code?
: All help we´ll be appiciated
: /Peter L
 
P

PeterL

clarification:
This is what I want to do:
1)Search the first date where the condition is met
2)list the fluids, volym and energi for this date
3) print out the sum of volym for this date
4) print out the sum of energi for this date
5) find the next date...
 
K

Ken Schaefer

That doesn't really clarify anything.

If you are looping through all the individual records, then use a temporary
variable to hold the summation of all the values prior to the next date.
Response.Write the value

Cheers
Ken

: clarification:
: This is what I want to do:
: 1)Search the first date where the condition is met
: 2)list the fluids, volym and energi for this date
: 3) print out the sum of volym for this date
: 4) print out the sum of energi for this date
: 5) find the next date...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top