Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2005, 06:13 AM
Friend of Wrox
 
Join Date: Jun 2003
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







 
Old May 1st, 2005, 01:35 PM
Friend of Wrox
 
Join Date: Jun 2003
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.
 
Old May 1st, 2005, 06:17 PM
Friend of Wrox
 
Join Date: Jan 2004
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
 
Old May 1st, 2005, 06:20 PM
Friend of Wrox
 
Join Date: Jan 2004
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
 
Old May 2nd, 2005, 03:11 AM
Friend of Wrox
 
Join Date: Jun 2003
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.