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 July 21st, 2003, 08:46 AM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP & SQL Database

I would like to add three columns from my sql database and multiply it by 0.5. How would I do this? Thanks.

 
Old July 22nd, 2003, 12:26 AM
Authorized User
 
Join Date: Jul 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First you have to open a RecosdSet, get these columns and then perform any calculations. A typical example is like this:

Dim strSQL,intCounter
Dim arraySum()
intCounter=0
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.Open "place the connection string here"
Set objRs=Server.CreateObject("ADODB.RecordSet")
strSQL="SELECT column1, column2, column3 FROM table_name WHERE your_conditions"

objRs.Open strSQL, objConn

Do While Not objRs.EOF
arraySum(intCounter)=cint(objRs("column1")+objRs(" column2")+objRs("column3"))
intCounter=intCounter + 1
 objRs.MoveNext
Loop

objRs.Close
Set objRs=Nothing
objConn.Close
Set objConn=Nothing

After that the arraySum contains the sums for each row of your three columns

Cheers
Kostas Lagos

 
Old July 22nd, 2003, 03:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

or you could just do it in SQL:
SELECT (Column1 + Column2 + Column3) * 0.5 As TheCalc FROM TableName





Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net & sql server database naeem.net ASP.NET 2.0 Professional 13 July 18th, 2007 02:10 PM
displaying records using asp & sql Adam H-W Classic ASP Databases 4 June 28th, 2006 08:41 AM
ASP & DTS in SQL server a_pathak SQL Server ASP 2 March 24th, 2004 12:48 AM
ASP & DTS in SQL server a_pathak SQL Server DTS 1 March 22nd, 2004 09:23 AM





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