473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Jul 19 '05 #1
3 1331
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" <pl*****@chello.se> wrote in message
news:72*************************@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
Jul 19 '05 #2
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...
Jul 19 '05 #3
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" <pl*****@chello.se> wrote in message
news:72************************@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...
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
9
by: Thomas R. Hummel | last post by:
Hello, I am importing data that lists rates for particular coverages for a particular period of time. Unfortunately, the data source isn't very clean. I've come up with some rules that I think...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
1
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
3
by: JJ | last post by:
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.