Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get The Total

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I am retrieving records of different categories that make a salary package & the corresponding amounts from SQL Server. Egs. of the different categories are HRA, CCA etc. which fall under the 'E' category (EARNINGS) & PF, PT, ITDS etc. which fall under the 'D' category (DEDUCTIONS). This is what I have done:

<%
iTotalE=0
iTotalD=0
Do Until(objRS3.EOF)
For iCol1=8 To objRS3.Fields.Count-1
ReDim iAmountE(iCol1)
ReDim iAmountD(iCol1)
If(Right(objRS3(iCol1).Name,1)=&quot;E&quot;) Then
iAmountE(iCol1)=Round(objRS3(iCol1))
Response.Write(&quot;<td valign=top>&quot; & iAmountE(iCol1) & &quot;.00<br>&quot;)
iTotalE=iAmountE(iCol1)+iTotalE
ElseIf(Right(objRS3(iCol1).Name,1)=&quot;D&quot;) Then
iAmountD(iCol1)=Round(objRS3(iCol1))
Response.Write(iAmountD(iCol1) & &quot;.00</td>&quot;)
iTotalD=iAmountD(iCol1)+iTotalD
End If
Next
Response.Write(&quot;<td>&quot; & iTotalE & &quot;.00<br>&quot; & iTotalD & &quot;.00</td>&quot;)
Response.Write(&quot;<th>&quot; & iTotalE-iTotalD & &quot;.00</th>&quot;)
objRS3.MoveNext
iTotalE=0
iTotalD=0
Loop
%>

The reason why I am using For....Next loop is because the alias column names are generated dynamically. To get the exact picture of how the records are displayed, please visit iTotalE & iTotalD generates the total of earnings & deductions respectively for each employee, say, iTotalE=HRA+CRE.. of each employee where as iTotalD=PF+PT

My question is how do I add up the, say, HRA of all employees, CRE of all employees, PF of all employees etc.? With respect to the above URL, how do I get the total 258786.00 under Basic (which is the total of Basic of all employees), 13500.00 under AD.SAL etc. Please note that in the <td>s where there are 2 categories shown, the categories which is at the top belong to the 'E' category where as those at the bottom belong to the 'D' category.

Thanks,

Arpan
 
How are you getting them now?

If you are using standard recordsets - what I do, might not be the most efficient method - but it is similiar to what you are now.

Dim strbasic
strBasicTTL=0


Then inside the loop - put

strBasicTTL=strBasicTTL + objRS3(&quot;HRA&quot;)


Then when your ready to show it a simple
<%=strBasicTTL%>
&quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Hello Friend,

Thanks for your reply. As you have shown, you are adding Basic with HRA which I don't want. What I want is the total HRA of all employees, the total CCA of all employees etc. It could even be a typing mistake where instead of objRS3(&quot;Basic&quot;), you have typed objRS3(&quot;HRA&quot;). Anyway, I had already thought of this solution but there is a problem in implementing it.

As I have already mentioned in my question, the reason why I am using For.....Next loop is because the alias column names are generated dynamically i.e. I don't know the column names while I am coding. Had I known the column alias names, say, HRA & CCA, I could have got the total with the following ASP code:

<%
iHRATotal=0
iCCATotal=0

Do Until(objRS3.EOF)
iHRA=objRS3(&quot;HRA&quot;)
iCCA=objRS3(&quot;CCA&quot;)
iHRATotal=iHRA+iHRATotal
iCCATotal=iCCA+iCCATotal
objRS3.MoveNext
Loop
Response.Write(iHRATotal & &quot;<br>&quot; & iCCATotal)
%>

But since I don't know the alias column names while coding, how do I get the total?

I hope you have understood what I am trying to say.

Thanks once again for your help,

Regards,

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top