Add or Sum variable in ASP 
Author Message
 Add or Sum variable in ASP

Hi I am having a problem to add or sum variable in ASP page
here is the scenario, I have one table in SQL server with couple
fields, user enter number into each fields, then I want add those
number in each field together, but I was unable to add those numbers,
here is my code
<%
Dim Conn
Dim rds
Dim osql

'Connection String to connect with the SQL server DB
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Driver={SQL Server};" & _
           "Server=webserver;" & _
           "Database=TechCensus;" & _
           "Uid=xxx;" & _
           "Pwd=xxxxxx;"

osql = "Select Appl68040Lab, Appl68040Room, Appl68040Center,
Appl68040Office, Appl68040Loc, TraceID from HsPartOne where TraceID =
'1222'"
Set rs = Conn.Execute(osql)

one = rs.fields("Appl68040Lab")

two = rs.fields("Appl68040Room")

three = rs.fields("Appl68040Center")
four = rs.fields("Appl68040Office")
five = rs.fields("Appl68040Loc")

%>
<%

total = one + two

response.write total

%><br>

If I run the following scripts, it does work the add function, I don't
know what is going on? Please help me, thanks in advance
<%
o = 1
a = 2

sum = o+a
response.write sum
%>



Tue, 06 Dec 2005 22:23:57 GMT  
 Add or Sum variable in ASP
What doesn't work?  You didn't say what is not working.  I'll take a guess
here and say that  if o = 1 and a = 2, your result is 12 instead of 3.  If
so, that's because you're concatenating your variables.  You'll have to
CInt/CLng, CSng, or CDbl your variables to let VB Script know that they're
numbers, not strings.

Ray at work


Quote:
> Hi I am having a problem to add or sum variable in ASP page
> here is the scenario, I have one table in SQL server with couple
> fields, user enter number into each fields, then I want add those
> number in each field together, but I was unable to add those numbers,
> here is my code
> <%
> Dim Conn
> Dim rds
> Dim osql

> 'Connection String to connect with the SQL server DB
> Set Conn = Server.CreateObject("ADODB.Connection")
> Conn.Open "Driver={SQL Server};" & _
>            "Server=webserver;" & _
>            "Database=TechCensus;" & _
>            "Uid=xxx;" & _
>            "Pwd=xxxxxx;"

> osql = "Select Appl68040Lab, Appl68040Room, Appl68040Center,
> Appl68040Office, Appl68040Loc, TraceID from HsPartOne where TraceID =
> '1222'"
> Set rs = Conn.Execute(osql)

> one = rs.fields("Appl68040Lab")

> two = rs.fields("Appl68040Room")

> three = rs.fields("Appl68040Center")
> four = rs.fields("Appl68040Office")
> five = rs.fields("Appl68040Loc")

> %>
> <%

> total = one + two

> response.write total

> %><br>

> If I run the following scripts, it does work the add function, I don't
> know what is going on? Please help me, thanks in advance
> <%
> o = 1
> a = 2

> sum = o+a
> response.write sum
> %>



Tue, 06 Dec 2005 22:27:54 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ASP, adding two variables

2. SUM...in ASP?

3. Calculate sum of times in ASP

4. SUM from a table in a variable

5. help: Crystal Reports with Variables and Sums

6. Adding Environmental Variable to System Variables thru VB

7. Adding and summing up database columns/rows

8. Trying to Add 2 Label totals (Sum)

9. AM I missing something - Sum and Cumulative Sum

10. Report showing BOTH Aggregate Sum of Display records and Total Sum by Group

11. How to sum a single fiscal period for monthly expenses and also sum ytd expenses

12. adding variable in document.add line

 

 
Powered by phpBB® Forum Software