SUM Function

# Thread: SUM Function

1. Senior Member
Join Date
Dec 1969
Posts
287

## SUM Function

I am still having difficulties with my sum function. This is the code, but it doesn&#039;t sum it, but adds the numbers together. For exmaple 10 and 10 should show 20 but it displays 1010. Where am I going wrong. Please help and thank you for all your help.<BR>Petra.<BR><BR><BR><BR> subtotal = subtotal + rs2.Fields("ExtCost")<BR> <BR><BR> Call Response.Write("&#060;/Tr&#062;")<BR><BR><BR> <BR>rs2.MoveNext<BR><BR><BR>WEND <BR><BR><BR><BR><BR>Response.Write("&#060;td size=0&#062;&#060;font size=0&#062;&#060;u&#062;" & FormatCurrency(subtotal) & "&#060;/td&#062;")

2. Senior Member
Join Date
Dec 1969
Posts
412

## RE: SUM Function

try this:<BR><BR>CLng(subtotal) + CLng(rs2.Fields("ExtCost"))<BR>

3. Senior Member
Join Date
Dec 1969
Posts
287

## Not working

I get an error, that the variable is not supported by VBScript. <BR>

4. Senior Member
Join Date
Dec 1969
Posts
1,032

## RE: SUM Function

subtotal = cdbl(subtotal) + cdbl(rs2.fields("ExtCost"))<BR><BR>???<BR><BR>jon

5. Senior Member
Join Date
Dec 1969
Posts
287

## WORKS!!! THANK YOU!!!

It works thank you soooooo much. PEtra

6. Senior Member
Join Date
Dec 1969
Posts
287

## One Last Question

What if I have Null values in the fields, than I get error again.<BR>What should I do?<BR>Thank you so much.

7. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## In your SQL statement..

.. change Null to 0.<BR><BR>Show the SELECT statement where you get the records from the table.

8. Senior Member
Join Date
Dec 1969
Posts
287

## Here is my SQL statement

strSQL = " SELECT * FROM [PONewTable] O WHERE O.ID=" & intID<BR> strSQL2 = "SELECT * FROM [podetailtable] D WHERE D.ID =" & intID<BR><BR>What do I have to change here?

9. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## First off, you shouldn't..

.. use SELECT *. You should select the individual fields that you need to select:<BR><BR>strSql2 = "SELECT D.FieldA, D.FieldB, D.FieldC, D.FieldD FROM [PODetailTable] D WHERE D.ID = " & intID<BR><BR>And, what database are you using? Access or Sql Server?

10. Senior Member
Join Date
Dec 1969
Posts
287

## RE: First off, you shouldn't..

Access

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•