Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 01:06 PM
PeterL
Guest
 
Posts: n/a
Default add up for each date

Hi,
I´ve the folloing code:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. pat = Request.Form("rapport")
  3. Set vbalans = Server.CreateObject("ADODB.Connection")
  4. vbalans.Provider = "Microsoft.Jet.OLEDB.4.0"
  5. MdbFilePath = Server.MapPath("\vatskebalans\db\vbalans.mdb")
  6. vbalans.ConnectionString = "Data Source='" & MdbFilePath & "'"
  7. vbalans.open
  8. strSQL = "SELECT f.FluidNamn, f.FluidID, v.Dag, v.PatID, v.Volym,
  9. v.Energi," &_
  10. " p.ftEnamn, p.ftFnamn FROM (tblVetskebalans v INNER JOIN
  11. tblFluids f"&_
  12. " ON v.FluidID = f.FluidID) INNER JOIN tblPersonuppgifter p
  13. ON v.PatID = p.PatID" &_
  14. " WHERE p.PatID = "& pat &""
  15. Set rs1 = vbalans.Execute (strSQL)
  16. 'formatera till svensk personnummer
  17. Function SvPnr(txt)
  18. personnummer =Left(txt,6) & " - " & Right(txt,4)
  19. SvPnr = personnummer
  20. End Function
  21. Function FirstVersal(txt)
  22. versal = UCase(Left(txt,1)) & LCase(Right(txt, Len(txt)-1))
  23. FirstVersal = versal
  24. End Function
  25. Response.Write SvPnr(rs1("PatID")) & "<BR>"
  26. Response.Write "<B>" & FirstVersal(rs1("ftEnamn")) & ", " &
  27. FirstVersal(rs1("ftFnamn")) & "</B><P><P><P>"
  28. %>
  29. <TABLE border=1>
  30. <TR>
  31. <TD><B>Datum</B></TD>
  32. <TD><B>Vätska</B></TD>
  33. <TD><B>Volym</B></TD>
  34. <TD><B>Energi</B></TD>
  35. </TR>
  36. <%
  37. v = 0
  38. e = 0
  39. dat = ""
  40. Do While Not rs1.EOF
  41. v = v + cint(rs1("Volym"))
  42. e = e + cint(rs1("Energi"))
  43. If dat <> CDate(rs1("Dag")) then
  44. dat = CDate(rs1("Dag"))
  45. Response.Write "<TR><TD>" & CDate(rs1("Dag"))& "</TD>"
  46. Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
  47. Response.Write "<TD>" & rs1("Volym") & "</TD>"
  48. Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
  49. Else
  50. Response.Write "<TR><TD> </TD>"
  51. Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
  52. Response.Write "<TD>" & rs1("Volym") & "</TD>"
  53. Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
  54. End If
  55. rs1.MoveNext
  56. Loop
  57.  
  58. vbalans.Close
  59. Set vbalans = Nothing
  60. %>
  61. </TABLE>
  62. <BR><BR><BR>
  63. <%
  64. Response.Write "<B><U>Totala volymen är</U></B>" & ":     " & v &
  65. "<BR>"
  66. Response.Write "<B><U>Totala energi är</U></B>" & ":        " & e &
  67. "<BR>"
  68.  
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
  #2  
Old July 19th, 2005, 01:06 PM
Ken Schaefer
Guest
 
Posts: n/a
Default Re: add up for each date

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


"PeterL" <plelkes@chello.se> wrote in message
news:7264667.0405032341.72e9ff61@posting.google.co m...
: Hi,
: I´ve the folloing code:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. : pat = Request.Form("rapport")
  3. : Set vbalans = Server.CreateObject("ADODB.Connection")
  4. : vbalans.Provider = "Microsoft.Jet.OLEDB.4.0"
  5. : MdbFilePath = Server.MapPath("\vatskebalans\db\vbalans.mdb")
  6. : vbalans.ConnectionString = "Data Source='" & MdbFilePath & "'"
  7. : vbalans.open
  8. : strSQL = "SELECT f.FluidNamn, f.FluidID, v.Dag, v.PatID, v.Volym,
  9. : v.Energi," &_
  10. :          " p.ftEnamn, p.ftFnamn FROM (tblVetskebalans v INNER JOIN
  11. : tblFluids f"&_
  12. :           " ON v.FluidID = f.FluidID) INNER JOIN tblPersonuppgifter p
  13. : ON v.PatID = p.PatID" &_
  14. :           " WHERE p.PatID = "& pat &""
  15. :   Set rs1 = vbalans.Execute (strSQL)
  16. : 'formatera till svensk personnummer
  17. : Function SvPnr(txt)
  18. :       personnummer =Left(txt,6) & " - " & Right(txt,4)
  19. :   SvPnr = personnummer
  20. : End Function
  21. : Function FirstVersal(txt)
  22. :       versal = UCase(Left(txt,1)) & LCase(Right(txt, Len(txt)-1))
  23. :   FirstVersal = versal
  24. : End Function
  25. :     Response.Write SvPnr(rs1("PatID")) & "<BR>"
  26. :     Response.Write "<B>" & FirstVersal(rs1("ftEnamn")) & ", " &
  27. : FirstVersal(rs1("ftFnamn")) & "</B><P><P><P>"
  28. : %>
  29. : <TABLE border=1>
  30. :   <TR>
  31. :     <TD><B>Datum</B></TD>
  32. :     <TD><B>Vätska</B></TD>
  33. :     <TD><B>Volym</B></TD>
  34. :     <TD><B>Energi</B></TD>
  35. :    </TR>
  36. : <%
  37. : v = 0
  38. : e = 0
  39. : dat = ""
  40. :  Do While Not rs1.EOF
  41. : v = v + cint(rs1("Volym"))
  42. : e = e + cint(rs1("Energi"))
  43. : If dat <> CDate(rs1("Dag")) then
  44. : dat = CDate(rs1("Dag"))
  45. :        Response.Write "<TR><TD>" & CDate(rs1("Dag"))& "</TD>"
  46. :        Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
  47. :        Response.Write "<TD>" & rs1("Volym") & "</TD>"
  48. :        Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
  49. :  Else
  50. :        Response.Write "<TR><TD> </TD>"
  51. :        Response.Write "<TD>" & rs1("FluidNamn") & "</TD>"
  52. :        Response.Write "<TD>" & rs1("Volym") & "</TD>"
  53. :        Response.Write "<TD>" & rs1("Energi") & "</TD></TR>"
  54. : End If
  55. : rs1.MoveNext
  56. : Loop
  57. :
  58. : vbalans.Close
  59. : Set vbalans = Nothing
  60. :  %>
  61. : </TABLE>
  62. : <BR><BR><BR>
  63. : <%
  64. : Response.Write "<B><U>Totala volymen är</U></B>" & ":     " & v &
  65. : "<BR>"
  66. : Response.Write "<B><U>Totala energi är</U></B>" & ":        " & e &
  67. : "<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


  #3  
Old July 19th, 2005, 01:07 PM
PeterL
Guest
 
Posts: n/a
Default Re: add up for each date

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...
  #4  
Old July 19th, 2005, 01:07 PM
Ken Schaefer
Guest
 
Posts: n/a
Default Re: add up for each date

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

"PeterL" <plelkes@chello.se> wrote in message
news:7264667.0405040501.1518b8b@posting.google.com ...
: 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...


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles