Skip to main content
Known Participant
June 29, 2009
Question

Calculating SUM in a Session Variable

  • June 29, 2009
  • 1 reply
  • 1010 views
I'm trying to create a session variable which will SUM 2 values from a Recordset:

<%
Session("TotalBeforeTax")=(rsOrderHistory.Fields.Item("OrderSubTotal").Value) + (rsOrderHistory.Fields.Item("OrderShipping").Value)
%>

Obviously, ASP doesn't like the + sign...
This topic has been closed for replies.

1 reply

Participating Frequently
June 29, 2009

>Obviously, ASP doesn't like the + sign...

This is not obvious to me. Why would ASP have a problem with the + ?   What error are you getting?


Is the statement split to two or more lines? If so, you need to use the line continuation character '_'

So:

<%
Session("TotalBeforeTax")=(rsOrderHistory.Fields.Item("OrderSubTotal").Value) + _

(rsOrderHistory.Fields.Item("OrderShipping").Value)
%>

BracholeAuthor
Known Participant
June 29, 2009

Say my OrderSubTotal is 589.8 and my OrderShipping is 59.9, I want it my session to be 649.7.

However, using the + sign, even the way you suggested, it will write: 589.859.9

In other words, in ASP, if you use the + sign between 2 recordset, it will display both:

Example:

(rsOrderHistory.Fields.Item("FirstName").Value) + (rsOrderHistory.Fields.Item("LastName").Value)

would display:

Joe Smith

I use thhe multiplication ( * ) and division ( / ) all the time, but for multiplication, not sure what to use...

Participating Frequently
June 29, 2009

OK, gotcha. The problem is that the values are being interpreted as string values. The + operator will concatenate the values if it interprets both as strings. A simple fix is to just convert them ( CDbl for example) in your expression.  I gotta run now but write back if you have problems with this.