Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 1st, 2005, 06:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculation in asp

How can do calculation in asp ?

ssql="select projno, Name, dept, BH, MH1 from tablename"

set rs=cn.Execute(ssql)

do while rs.eof=false

Response.Write("<td align=center>" & rs("empno") & "</td>")
Response.Write("<td align=center>" & rs("projno") & "</td>")
Response.Write("<td align=center>" & rs("BH") & "</td>")
Response.Write("<td align=center>" & rs("MH1") & "</td>")
....
rs.movenext

loop

data retrieve in asp table like this.

empno...projno....BH....MH1
----------------------------
12345...2016.....200....40
45612...2016.....170....50
12349...2016.....200....30
----------------------------
.....................570...120

horizontally (row wise) data can add/(sum) like this.

MH1=rs("MH1")
BH=rs("BH")

total=MH1+BH

my problem is how can add/sum MH1 and BH which is displaying
in vertically (column wise) ?
ie

total BH=570 and MH1=120 how can calculate in above loop ?
and also display in above loop table ?

regards.

Mateen







Reply With Quote
  #2 (permalink)  
Old May 1st, 2005, 01:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just keep two variables and increment them with the values as you progress through the loop. Alternatively you could use a second SQL command to get the totals from the database.
Reply With Quote
  #3 (permalink)  
Old May 1st, 2005, 06:17 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Dim totalBH, totalMH1
totalBH = 0
totalMH1 = 0
If not rs.Eof then
   do while rs.eof=false
      Response.Write("<td align=center>" & rs("empno") & "</td>")
      Response.Write("<td align=center>" & rs("projno") & "</td>")
      totalBH = (totalBH & rs("BH"))
      Response.Write("<td align=center>" & rs("BH") & "</td>")
      totalMH1 = totalMH1 & rs("MH1")
      Response.Write("<td align=center>" & rs("MH1") & "</td>")
      rs.movenext
   loop
   response.write "<tr>" & _
                    "<td colspan='2'>&nbsp;</td>" & _
                    "<td>" & totalBH & "</td>" & _
                    "<td>" & totalMH1 & "</td>" & _
                  "</tr>"
end if

Wind is your friend
Matt
Reply With Quote
  #4 (permalink)  
Old May 1st, 2005, 06:20 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Correction above, change:
totalBH = (totalBH & rs("BH")) and totalMH1 = totalMH1 & rs("MH1")
to:
totalBH = (totalBH + cInt(rs("BH"))) and totalMH1 = totalMH1 + cInt(rs("MH1"))


Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old May 2nd, 2005, 03:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lot of thanks for your response.

I use use your code like this.

dim totalBH, total2, totalMH1, per

IF NOT RS.EOF THEN
do while rs.eof=false

Response.Write("<td align=center>" & rs("empno") & "</td>")
Response.Write("<td align=center>" & rs("projno") & "</td>")

totalBH = (totalBH + cint(rs("BH")))

Response.Write("<td align=center>" & rs("BH") & "</td>")

totalMH1 = (totalMH1 + cint(rs("MH1")))

Response.Write("<td align=center>" & rs("mh1") & "</td>")
.......

total2 = (total2 + cint(rs("total")))

Response.Write("<td align=center>" & rs("total") & "</td>")
Response.Write("<td>&nbsp;</td>")


rs.movenext

loop

per = (total2/totalBH)*100

per=round(per,2)

Response.Write "<tr>" & _
                    "<td colspan='3'>&nbsp;</td>" & _
                    "<td align=center>" & totalBH & "</td>" & _
                    "<td align=center>" & totalMH1 & "</td>" & _
                    "<td>&nbsp;</td>" & _
                    "<td>&nbsp;</td>" & _
                    "<td>&nbsp;</td>" & _
                    "<td>&nbsp;</td>" & _
                    "<td align=center>" & total2 & "</td>" & _
                    "<td align=center>" & per & "</td>" & _
                    "<tr>"

end if

I use following query with group by

ssql="select a.projno, e.Name, e.dept,a.empno,b.dated,b.bh, sum(total) total
.....
where b.dated='"& DATED &"' and
a.projno='"& projno &"'
group by a.projno ,e.dept,e.name,a.empno,b.bh,b.dated
order by e.DEPT,E.NAME,a.projno"

data display in asp page like this.

date:4/27/2005
empno..dept...projno....BH......total....
-------------------------------------------------------------
12345...highway..2016.....200...100
45612...highway..2016.....170...150
12349...highway..2016.....200...100
56545...Account..2016.....250...110
56444...Account..2016.....200...150
21545...Account..2016.....150...100
--------------------------------------------------------------
.....................................1170...710


I want to retrieve data and calculation in asp page like this with calculation

date:4/27/2005
empno..dept...projno......BH......total...&Utilize d.
------------------------------------------------------
12345...highway..2016.....200...100
45612...highway..2016.....170...150
12349...highway..2016.....200...100
.....................................570....350... .61.40

56545...Account..2016.....250...110
56444...Account..2016.....200...150
21545...Account..2016.....150...100
--------------------------------------------------
.....................................600....360... .61.40


350/570*100=61.40
360/600*100=60.00

1. display sum/total with department wise and also calculate
%Utilized as above ?

2. what change in asp loop, it display data as above ?
3. or what change in sql query that it display data as above ?
4. or how can use the query in above loop that it display
   data department wise ?

Please help.

regards.

Mateen
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Age Calculation rgerald SQL Server 2000 32 October 10th, 2007 01:12 AM
calculation operation vinny07 Excel VBA 0 March 1st, 2007 06:32 AM
CLIENT SIDE TIME CALCULATION IN ASP.NET gmk51080 Javascript How-To 1 December 1st, 2004 01:29 AM
client side time calculation in asp.net gmk51080 Javascript 0 November 30th, 2004 04:07 AM
Calculation Grantm Access 3 February 16th, 2004 10:14 AM



All times are GMT -4. The time now is 06:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.